Example #1
0
        /// <summary>
        /// change user password
        /// </summary>
        /// <param name="oldPassword">old password</param>
        /// <param name="newPassword">new password</param>
        public void ChangePassword(string loginName, string oldPassword, string newPassword)
        {
            UserAccountEntity userEntity = null;

            try
            {
                userEntity = QuickRepository.GetDefaultByName <UserAccountEntity>("LoginName", loginName);
                var isChecked = CheckPassword(userEntity, oldPassword);     //it's better to limit wrong password 3 or 6 times to prevent someone crack the account
                if (!isChecked)
                {
                    throw new ApplicationException("用户名和密码不匹配,请重试.");
                }
            }
            catch (System.ApplicationException ex)
            {
                throw new ApplicationException("修改密码发生错误!");
            }

            try
            {
                var saltText = string.Empty;
                EnumHashProvider hashProvider;
                var encryptedPwd = HashingAlgorithmUtility.GetEncryptedHashText(newPassword, out saltText, out hashProvider);

                userEntity.Password       = encryptedPwd;
                userEntity.PasswordFormat = (short)hashProvider;
                userEntity.PasswordSalt   = saltText;

                QuickRepository.Update <UserAccountEntity>(userEntity);
            }
            catch (System.ApplicationException ex)
            {
                throw;
            }
        }
Example #2
0
        /// <summary>
        /// user register
        /// </summary>
        /// <param name="account"></param>
        public void Register(UserAccountEntity account)
        {
            //verify input validation
            var result     = ResponseResult.Default();
            var userEntity = QuickRepository.GetDefaultByName <UserAccountEntity>("LoginName", account.LoginName);

            if (userEntity != null)
            {
                throw new ApplicationException("用户名已经被占用,请重新存在!");
            }
            else if (string.IsNullOrEmpty(account.Password) || account.Password.Length < 6)
            {
                throw new ApplicationException("密码不能为空,或者长度不能小于6位!");
            }

            //create
            try
            {
                QuickRepository.Insert <UserAccountEntity>(account);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Example #3
0
        /// <summary>
        /// get user login name
        /// </summary>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public UserAccountEntity GetByLoginName(string loginName)
        {
            var user = QuickRepository.GetDefaultByName <UserAccountEntity>("LoginName", loginName);

            return(user);
        }
Example #4
0
        /// <summary>
        /// get user by email
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public UserAccountEntity GetByEmail(string email)
        {
            var user = QuickRepository.GetDefaultByName <UserAccountEntity>("EMail", email);

            return(user);
        }