示例#1
0
        // returns true if password successfully changed
        public static bool ChangePass(Users user, string oldPassword, string newPassword)
        {
            user.BytKey      = ComputeSHA256Hash(oldPassword, user.BytSalt);
            user.StrPassword = oldPassword;
            if (VerifyUser(user))
            {
                InsertDAL insertDAL = new InsertDAL();
                insertDAL.OpenConnection();

                byte[] newKey;
                try
                {
                    newKey = ComputeSHA256Hash(newPassword, user.BytSalt);
                } catch (ArgumentNullException)
                {
                    return(false);
                }

                insertDAL.UpdateUserKey(user.IntUserID, newKey);

                insertDAL.CloseConnection();

                return(true);
            }

            return(false);
        }
示例#2
0
        // returns true if new user is created successfully
        public static bool CreateUser(Users newUser)
        {
            GetDAL getDAL = new GetDAL();

            getDAL.OpenConnection();

            Users usr = getDAL.GetUserByName(newUser.StrName);

            // if no user found by username
            if (usr == null)
            {
                // prompt for name, email, phone, eventID

                // get email
                string email = newUser.StrEmail;
                if (!IsValidEmail(email))
                {
                    return(false);
                }

                // get phone
                string phone = newUser.StrPhone;
                if (phone.Length != 10)
                {
                    return(false);
                }

                InsertDAL insertDAL = new InsertDAL();
                insertDAL.OpenConnection();

                // generate random number for salt and convert it to a byte array for key
                byte[] salt = BitConverter.GetBytes(new Random().Next());
                byte[] key;
                try
                {
                    key = ComputeSHA256Hash(newUser.StrPassword, salt);
                } catch (ArgumentNullException)
                {
                    return(false);
                }

                int intNewUserID = insertDAL.InsertUser(new Users(newUser.StrName, salt, key, email, phone));

                insertDAL.CloseConnection();

                GetDAL get = new GetDAL();
                get.OpenConnection();

                Users completeUser = get.GetUserByID(intNewUserID);

                get.CloseConnection();

                return(LoginUser(completeUser));
            }

            getDAL.CloseConnection();

            return(false);
        }