ChangePassword Method for Entity Framework MVC3 Razor Custom Member Provider C# Using LINQ
From my
C# MVC3 Razor Custom Membership Provider article and source code, here is the code for the ChangePassword method. I welcome any suggestions for improvement.
public override bool ChangePassword(string username,
string oldPassword, string newPassword)
{
try
{
byte[] hashedNewPassword = HashPassword(newPassword.Trim());
byte[] hashedOldPassword = HashPassword(oldPassword.Trim());
using (var context = new SSSEntities())
{
UserProfile u = context.UserProfiles
.SingleOrDefault(up => up.UserName == username &&
up.UserPassword == hashedOldPassword);
if (u != null)
{
u.UserPassword = hashedNewPassword;
context.SaveChanges();
return true;
}
else
return false;
}
}
catch (InvalidOperationException ex)
{
throw ex;
}
catch (ArgumentException)
{
throw;
}
}May your dreams be in ASP.NET!
Nannette Thacker