Inheritance: System.Data.Objects.DataClasses.EntityObject
Exemplo n.º 1
0
        public bool createUser(int UserID, int UserType, string password, string name, string email, DateTime Expires_At, int SysAdmin_ID)
        {
            if (sysAdminExist(email))
                return false;
            string Salt = CreateSalt(10);
            string hshdpwd = CreatePasswordHash(password, Salt);

            try
            {
                USER create = new USER();

                create.USER_ID = UserID;
                create.USER_TYPE = UserType;
                create.PASSWORD = hshdpwd;
                create.SALT = Salt;
                create.USERNAME = email;
                create.NAME = name;
                create.EXPIRES_AT = Expires_At;
                create.CREATED_AT = DateTime.Now;
                create.MODIFIED_AT = DateTime.Now;
                create.SYSADMIN_ID = SysAdmin_ID;
                create.RESET_PASSWORD_KEY = "Created";

                dbpollContext.AddToUSERS(create);
                dbpollContext.SaveChanges();
            }
            catch (Exception e)
            {
                throw (e);
            }
            return true;
        }
Exemplo n.º 2
0
        public int verify_as_sys_admin(string username, string password)
        {
            CultureInfo ci = Thread.CurrentThread.CurrentCulture;
            ci = new CultureInfo("en-AU");
            Thread.CurrentThread.CurrentCulture = ci;
            string Salt = "";
            string hshdpwd = "";

            userModel user = null;
            try
            {
                var userList = from u in dbpollContext.SYSADMINS
                               where (u.USERNAME == username)
                               select new userModel
                               {
                                   UserID = u.SYSADMINS_ID,
                                   Salt = u.SALT,
                                   password = u.PASSWORD
                               };

                user = userList.ToList()[0];
            }
            catch (Exception e)
            {
                return 0;
            }
            Salt = user.Salt;
            hshdpwd = CreatePasswordHash(password, Salt);

            //compared hashed password from input, against password from db
            if (hshdpwd.Equals(user.password))
                return user.UserID;
            else
                return 0;

            //var query = from u in dbpollContext.SYSADMINS
            //            where (u.USERNAME == username && u.PASSWORD == password)
            //            select u;

            //if (query.ToArray().Length == 1)
            //{
            //    return query.ToArray()[0].SYSADMINS_ID;
            //}
            //else
            //{
            //    return 0;
            //}
        }
Exemplo n.º 3
0
        /// <summary>
        /// Takes a username and checks the user exists in the system and returns
        /// the user's userid code.
        /// </summary>
        /// <param name="username">username of user to verify</param>
        /// <returns>USERID that corresponds to user
        /// or returns 0 if they do not exist</returns>
        public int verify(string username)
        {
            CultureInfo ci = Thread.CurrentThread.CurrentCulture;
            ci = new CultureInfo("en-AU");
            Thread.CurrentThread.CurrentCulture = ci;

            userModel user = null;
            try
            {
                var query = from u in dbpollContext.USERS
                            where (u.USERNAME == username)
                            select new userModel
                            {
                                UserID = u.USER_ID,
                                Expires_At = (DateTime)u.EXPIRES_AT
                            };

                user = query.ToList()[0];
                return user.UserID;
            }
            catch (Exception e)
            {
                return 0;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Takes a username and password, checks the user exists in the system and returns
        /// the user's userid code.
        /// </summary>
        /// <param name="username">username of user to verify</param>
        /// <param name="password">password of user to verify</param>
        /// <returns>USERID that corresponds to user
        /// or returns 0 if they do not exist</returns>
        public int verify(string username, string password)
        {
            CultureInfo ci = Thread.CurrentThread.CurrentCulture;
            ci = new CultureInfo("en-AU");
            Thread.CurrentThread.CurrentCulture = ci;
            string Salt = "";
            string hshdpwd = "";

            userModel user = null;
            try
            {
                var userList = from u in dbpollContext.USERS
                               where (u.USERNAME == username)
                               where u.USER_TYPE != -1
                               select new userModel
                               {
                                   UserID = u.USER_ID,
                                   Salt = u.SALT,
                                   password = u.PASSWORD,
                                   Reset_Password_Key = u.RESET_PASSWORD_KEY
                               };

                user = userList.ToList()[0];
            }
            catch (Exception e)
            {
                return 0;
            }
            Salt = user.Salt;
            hshdpwd = CreatePasswordHash(password, Salt);

            //compared hashed password from input, against password from db
            if (hshdpwd.Equals(user.password))
                return user.UserID;
            else
                return 0;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the USERS EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUSERS(USER uSER)
 {
     base.AddObject("USERS", uSER);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Create a new USER object.
 /// </summary>
 /// <param name="uSER_ID">Initial value of the USER_ID property.</param>
 /// <param name="uSER_TYPE">Initial value of the USER_TYPE property.</param>
 /// <param name="cREATED_AT">Initial value of the CREATED_AT property.</param>
 public static USER CreateUSER(global::System.Int32 uSER_ID, global::System.Int32 uSER_TYPE, global::System.DateTime cREATED_AT)
 {
     USER uSER = new USER();
     uSER.USER_ID = uSER_ID;
     uSER.USER_TYPE = uSER_TYPE;
     uSER.CREATED_AT = cREATED_AT;
     return uSER;
 }