コード例 #1
0
ファイル: ZentityUser.cs プロジェクト: Plankankul/Zenity
 /// <summary>
 /// Generates a new password for the user in case he forgets the password
 /// </summary>
 /// <param name="logOnName">Log on name</param>
 /// <param name="securityQuestion">Security question</param>
 /// <param name="answer">Answer to security question</param>
 /// <returns>New password generated for the user</returns>
 /// <remarks>In case user forgets his password the security API gives him a new system generated password.
 /// Set user's logon name, security question and answer properties to correct
 /// values (those matching ones entered at the time of user registration) and then call this method. 
 /// It returns a system generated strong password of minimum length as specified by the password policy
 /// </remarks>
 /// <exception cref="System.ArgumentException">Thrown when this method is called without first setting the 
 /// logon name, security question or answer of the ZentityUser object.</exception>
 /// <example>
 /// <code>
 /// try
 ///    {
 ///        //In case user forgets his password the security API gives him a new system generated password.  
 ///        //User needs to provide security question and answer which he had entered at the time of registration.
 ///        
 ///        //Create an instance of ZentityUser and set logon name, security question and answer.
 ///        ZentityUser user = new ZentityUser { LogOnName = &quot;john&quot; };
 ///        user.SetSecurityQuestion(&quot;What is a bit?&quot;);
 ///        user.SetAnswer(&quot;0 or 1&quot;);
 ///        //Call ForgotPassword method. It returns a new strong password which is of minimum length specified in password policy. 
 ///        string newSystemGeneratedPassword = user.ForgotPassword();
 ///        if (!string.IsNullOrEmpty(newSystemGeneratedPassword))
 ///        {
 ///            Console.WriteLine(&quot;Your new password is {0}&quot;, newSystemGeneratedPassword);
 ///        }
 ///        else
 ///        {
 ///            Console.WriteLine(&quot;Errors in generating new password. Please verify that logon name, security question and answer are correct.&quot;);
 ///        }
 ///    }
 ///    catch (AuthenticationException ex)
 ///    {
 ///        //    AuthenticationException may be thrown in case of database errors
 ///        Console.WriteLine(ex.Message);
 ///        //    In case of database errors the AuthenticationException object will wrap the sql exception. 
 ///        if (ex.InnerException != null)
 ///        {
 ///            Console.WriteLine(ex.InnerException.Message);
 ///        }
 ///    }
 ///
 /// </code>
 /// </example>
 public static string ForgotPassword(string logOnName, string securityQuestion, string answer)
 {
     string newPassword = PasswordManager.ForgotPassword(
                                                 logOnName,
                                                 securityQuestion,
                                                 HashingUtility.GenerateHash(answer.ToUpper(CultureInfo.CurrentCulture)));
     return newPassword;
 }
コード例 #2
0
ファイル: ZentityUserAdmin.cs プロジェクト: Plankankul/Zenity
        /// <summary>
        /// Resets password for a user who has forgotten both his password as well as security question and answer.
        /// </summary>
        /// <param name="logOnName">Log on name</param>
        /// <returns>List of available account status values.</returns>
        public string ResetPassword(string logOnName)
        {
            #region Parameter Validation
            if (string.IsNullOrEmpty(logOnName))
            {
                throw new ArgumentNullException("logOnName");
            }
            #endregion
            ZentityUserProfile userProfile = DataAccessLayer.GetUserProfile(logOnName);
            if (userProfile != null)
            {
                string newPassword = PasswordManager.ForgotPassword(
                    userProfile.LogOnName,
                    userProfile.SecurityQuestion,
                    userProfile.Answer);
                return(newPassword);
            }

            return(string.Empty);
        }