/// <summary> /// Returns number of days remaining for password expiry for the user represented by logOnName. /// </summary> /// <param name="token">AuthenticatedToken of the logged on user, typically an admin.</param> /// <param name="logOnName">LogOnName of the user whose information is requested.</param> /// <returns>Remaining days, if operation succeeds, null otherwise.</returns> /// <remarks>Call this method when an admin wants information for a user. For a user requesting his information, /// call the overload with just AuthenticatedToken parameter.</remarks> public static int?GetRemainingDaysToPasswordExpiry(AuthenticatedToken token, string logOnName) { //// Input Validation ValidateToken(token); ValidateParameters("logOnName", logOnName); try { //// The token must be of the user who is updating the logon name or it must be an admin's token. if (!string.Equals(token.IdentityName, logOnName, StringComparison.OrdinalIgnoreCase) && !DataAccessLayer.IsAdmin(token.IdentityName)) { return(null); } ZentityUser user = new ZentityUser(logOnName, token); int? remainingDays = user.GetRemainingDaysToPasswordExpiry(); return(remainingDays); } catch (TypeInitializationException ex) { //// thrown in case of incorrect application configuration throw new AuthenticationException(ConstantStrings.TypeInitializationExceptionMessage, ex); } }
/// <summary> /// Returns number of days remaining before the password expires. /// </summary> /// <param name="logOnName">Logon name of the user</param> /// <param name="password">User password</param> /// <returns>Remaining days for password expiry. </returns> /// <remarks>Useful for displaying warning to the user that he needs to change his password in n days</remarks> /// <example> /// Pre-requisites for running this code sample /// <list type="bullet"> /// <item>Refer to the sample application configuration file given in help, and create a similar one for your application.</item> /// <item>Add reference to Zentity.Security.Authentication.dll and Zentity.Security.AuthenticationProvider.dll </item> /// <item>Run the sample for registering new users to create the user accounts in the authentication database.</item> /// <item>Then run this sample, replacing inputs with valid values</item> /// </list> /// For a complete sample please refer to ZentityUser.GetRemainingDaysToPasswordExpiry() documentation /// <code> /// try /// { /// //This method returns the number of days remaining for password expiry of the user, as per the /// //password policy. /// //Typically useful for showing reminder message to the user when he logs in. /// int? remainingDays = ZentityUserManager.GetRemainingDaysToPasswordExpiry("JohnDE", "john@123"); /// Console.WriteLine("Your password expires in {0} days", remainingDays); /// } /// catch (AuthenticationException ex) /// { /// 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> /// <seealso cref="ZentityUser.GetRemainingDaysToPasswordExpiry"/> public static int?GetRemainingDaysToPasswordExpiry(string logOnName, string password) { #region Input Validation ValidateParameters("logOnName", logOnName, "password", password); #endregion try { ZentityUser user = new ZentityUser(logOnName, password); int? remainingDays = user.GetRemainingDaysToPasswordExpiry(); return(remainingDays); } catch (TypeInitializationException ex) { //// thrown in case of incorrect application configuration throw new AuthenticationException(ConstantStrings.TypeInitializationExceptionMessage, ex); } }