Esempio n. 1
0
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="user">用户对象</param>
        /// <param name="password">需要加密的密码</param>
        /// <returns></returns>
        public bool ResetPassword(User user, string newPassword)
        {
            if (string.IsNullOrWhiteSpace(newPassword))
            {
                return(false);
            }

            var md5Password = UserPasswordHelper.EncodePassword(newPassword, UserPasswordFormat.MD5);
            var result      = userRepository.ResetPassword(user, md5Password);

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 创建用户
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password">密码</param>
        /// <param name="passwordQuestion">密码问题</param>
        /// <param name="passwordAnswer">密码答案</param>
        /// <param name="ignoreUsername">是否忽略禁用的用户名称</param>
        /// <param name="userCreateStatus">创建状态</param>
        /// <returns></returns>
        public User CreateUser(User user, string password, string passwordQuestion, string passwordAnswer, bool ignoreUsername, out UserCreateStatus userCreateStatus)
        {
            if (user == null)
            {
                userCreateStatus = UserCreateStatus.UnknownFailure;
                return(null);
            }
            string errorMessage = string.Empty;

            if (!Utility.ValidatePassword(password, out errorMessage))
            {
                userCreateStatus = UserCreateStatus.InvalidPassword;
                return(null);
            }
            user.PasswordFormat   = (int)UserPasswordFormat.MD5;
            user.Password         = UserPasswordHelper.EncodePassword(password, UserPasswordFormat.MD5);
            user.PasswordQuestion = passwordQuestion;
            user.PasswordAnswer   = passwordAnswer;
            user.IsModerated      = false;

            user = userRepository.CreateUser(user, ignoreUsername, out userCreateStatus);
            return(user);
        }
Esempio n. 3
0
        /// <summary>
        /// 验证用户名和密码是否匹配
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="passWord">密码</param>
        /// <returns>登录状态枚举</returns>
        public UserLoginStatus ValidateUser(string userName, string passWord)
        {
            long userId = UserIdToUserNameDictionary.GetUserId(userName);
            User user   = userRepository.GetUser(userId);

            if (user == null)
            {
                return(UserLoginStatus.InvalidCredentials);
            }
            if (!userName.Equals(user.UserName, StringComparison.CurrentCulture))
            {
                return(UserLoginStatus.InvalidCredentials);
            }
            if (!UserPasswordHelper.CheckPassword(passWord, user.Password, (UserPasswordFormat)user.PasswordFormat))
            {
                return(UserLoginStatus.InvalidCredentials);
            }
            if (!user.IsActivated)
            {
                return(UserLoginStatus.NotActivated);
            }
            if (user.IsBanned)
            {
                if (user.BanDeadLine >= DateTime.UtcNow)
                {
                    return(UserLoginStatus.Banned);
                }
                else
                {
                    user.IsBanned    = false;
                    user.BanDeadLine = DateTime.UtcNow;
                    userRepository.Update(user);
                }
            }

            return(UserLoginStatus.Success);
        }