public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
This register function is called after I fill in the registration form but I have just replace the default mdf database with a newly created sdf database, I would also like to use the md5 to hash the member’s password. Where should I add in such function in the source above ?
[UPDATE]
It looks like you’re using the ASP.Net membership API to accomplish this. Knowing that, I’d attempt to keep the code you’re using against this API faithful to the purpose of the API. I’d not hash the password before passing it to the API. I’d hash it within the MembershipProvider before saving the password; and I’d hash it before any password validation routine. This would keep the details of the implementation of your password hashing outside of your application code, who’s only knowledge would be how to interface with the ASP.Net Membership API.
So, you should look into how your MembershipProvider is configured. I’m unsure if the default SQL MembershipProvider is capable of doing this automatically, but if so, that’d be wonderful. Otherwise, you might override the SQL MembershipProvider with your own implementation.
Consult as a starting point [1], which describes the SqlMembershipProvider class.
[1] http://msdn.microsoft.com/en-us/library/system.web.security.sqlmembershipprovider.aspx