示例#1
0
 /// <summary>
 /// Set new password for user
 /// </summary>
 /// <param name="user"></param>
 /// <param name="newPassword">If null, random password will be generated and returned</param>
 /// <returns></returns>
 public static string SetNewPassword(this PersonalAccountUser user, string newPassword = null)
 {
     user.Hint1 = Membership.GeneratePassword(8, 3);
     user.Hint2 = Membership.GeneratePassword(8, 3);
     if (newPassword == null)
     {
         newPassword = Membership.GeneratePassword(6, 0);
         var rand = new Random();
         newPassword = Regex.Replace(newPassword, @"[^a-zA-Z0-9]", m =>
         {
             return(rand.Next(10).ToString());
         });
     }
     user.PasswordHash = CreateMD5(user.Hint1 + newPassword + user.Hint2);
     return(newPassword);
 }
示例#2
0
 public static bool CheckPassword(this PersonalAccountUser user, string password)
 {
     return(CreateMD5(user.Hint1 + password + user.Hint2) == user.PasswordHash);
 }