public ActionResult Register(RegisterModel RegisterModel, string returnUrl)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Byte[] Password = encoding.GetBytes(RegisterModel.Password);
var EncryptedPass = MembershipProvider.EncryptPassword(Password);
Membership.CreateUser(RegisterModel.UserName, RegisterModel.Password, RegisterModel.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(RegisterModel.UserName, false /* createPersistentCookie */);
return Redirect(returnUrl ?? Url.Action("Index", "Education"));
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
return View(RegisterModel);
}
Trying to encrypt a password before storing it in the database using the EncryptPassword method and then Dycrypt it with MembershipProvider.DecryptPassword Method but getting a ‘Is inaccessible due to its protection level’ error warning.
Because both
MembershipProvider.EncryptPasswordandMembershipProvider.DecryptPasswordmethod are protected.So, You will not be able to access them out side the class or its derived class definition.
And while creating any user via
Membership.CreateUserit automatically encrypt the password.