コード例 #1
0
        /// <summary>
        /// Updates the password question and answer.
        /// </summary>
        /// <param name="passwordQuestion">The password question</param>
        /// <param name="passwordAnswer">The password answer</param>
        /// <remarks>This method does not save the user record.</remarks>
        public void SetPasswordQuestion(string passwordQuestion, string passwordAnswer)
        {
            this.PasswordQuestion = passwordQuestion;
            string encodedPasswordAnswer = string.Empty;

            if (!string.IsNullOrEmpty(passwordAnswer))
            {
                encodedPasswordAnswer = UserPasswordHelper.EncodePassword(passwordAnswer, "SHA1");
            }
            this.PasswordAnswer = encodedPasswordAnswer;
        }
コード例 #2
0
        /// <summary>
        /// Processes a request to update the password question and answer for a membership user.
        /// </summary>
        /// <param name="username">The user to change the password question and answer for. </param>
        /// <param name="password">The password for the specified user.</param>
        /// <param name="newPasswordQuestion">The new password question for the specified user</param>
        /// <param name="newPasswordAnswer">The new password answer for the specified user. </param>
        /// <returns>true if the password question and answer are updated successfully; otherwise, false.</returns>
        public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
        {
            User user = UserDataSource.LoadForUserName(username);

            if ((user != null) && user.CheckPassword(password))
            {
                user.PasswordQuestion = newPasswordQuestion;
                //password answer is always encoded in SHA1
                user.PasswordAnswer = UserPasswordHelper.EncodePassword(newPasswordAnswer, "SHA1");
                return(user.Save() != SaveResult.Failed);
            }
            return(false);
        }
コード例 #3
0
ファイル: UserEditModel.cs プロジェクト: yuluoqian/ChiakiYu
        public User AsUser()
        {
            var user = new User
            {
                UserName       = UserName,
                NickName       = NickName,
                PasswordFormat = UserPasswordFormat.Md5,
                Password       = UserPasswordHelper.EncodePassword("123456", UserPasswordFormat.Md5),
                AccountEmail   = AccountEmail,
                AccountMobile  = AccountMobile
            };

            return(user);
        }
コード例 #4
0
        /// <summary>
        /// Updates the user password
        /// </summary>
        /// <param name="newPassword">new password</param>
        /// <param name="forceExpiration">force expiration</param>
        /// <returns>True if the password was set successfully; false otherwise</returns>
        public bool SetPassword(string newPassword, bool forceExpiration)
        {
            bool           isAdmin = this.IsAdmin;
            PasswordPolicy policy;

            if (isAdmin)
            {
                policy = new MerchantPasswordPolicy();
            }
            else
            {
                policy = new CustomerPasswordPolicy();
            }
            int      historyDays      = policy.HistoryDays;
            int      historyCount     = policy.HistoryCount;
            DateTime lastPasswordDate = LocaleHelper.LocalNow.AddDays(-1 * historyDays);
            UserPasswordCollection passwordCollection = this.Passwords;
            int passwordCount = passwordCollection.Count;

            for (int i = passwordCount - 1; i >= 0; i--)
            {
                UserPassword oldPassword = passwordCollection[i];
                if ((oldPassword.PasswordNumber >= historyCount) && (oldPassword.CreateDate <= lastPasswordDate))
                {
                    passwordCollection[i].Delete();
                    passwordCollection.RemoveAt(i);
                }
                else
                {
                    passwordCollection[i].PasswordNumber++;
                }
            }
            UserPassword userPassword = new UserPassword();

            userPassword.Password        = UserPasswordHelper.EncodePassword(newPassword, policy.PasswordFormat);
            userPassword.PasswordFormat  = policy.PasswordFormat;
            userPassword.PasswordNumber  = 1;
            userPassword.CreateDate      = LocaleHelper.LocalNow;
            userPassword.ForceExpiration = forceExpiration;
            passwordCollection.Add(userPassword);
            this.LastPasswordChangedDate = userPassword.CreateDate;
            bool result = (this.Save() != SaveResult.Failed);

            if (isAdmin)
            {
                Logger.Audit(AuditEventType.PasswordChanged, result, string.Empty);
            }
            return(result);
        }
コード例 #5
0
        public JsonResult _Step2_Install_InitialData()
        {
            ConcurrentDictionary <string, string> messages = new ConcurrentDictionary <string, string>();
            string connectString = Request.Form.Get <string>("connectString", string.Empty);
            //连接新库
            SqlConnection dbConnection = GetSqlConnection(connectString, out messages);

            if (messages.Keys.Count > 0)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "连接字符串不对!")));
            }
            string administrator = Request.Form.Get <string>("Administrator", string.Empty);
            string userPassword  = Request.Form.Get <string>("UserPassword", string.Empty);
            KeyValuePair <string, string> adminInfo = new KeyValuePair <string, string>(administrator, UserPasswordHelper.EncodePassword(userPassword, Tunynet.Common.UserPasswordFormat.MD5));
            string        mainRootSiteUrl           = Request.Form.Get <string>("MainRootSiteUrl", string.Empty);
            List <string> fileList = SetupHelper.GetInstallFiles(null, true).Where(n => n.Contains("InitialData") || n.Contains("CreateAdministrator")).ToList();
            string        message  = string.Empty;

            foreach (var file in fileList)
            {
                try
                {
                    SetupHelper.ExecuteInFile(dbConnection, file, out messages, adminInfo, mainRootSiteUrl);
                }
                catch { }
                if (messages.Count > 0)
                {
                    WriteLogFile(messages);
                    return(Json(new StatusMessageData(StatusMessageType.Error, "执行数据库初始化脚本时出现错误,请查看安装日志!")));
                }
            }
            return(Json(new StatusMessageData(StatusMessageType.Success, "安装数据库表结构成功!")));
        }