Reputation: 266
I have used the following code for user registeration.When i debugged the code password is in encrypted form but it is stored as plain text.Password salt has been also stored in db.
[HttpPost, RecaptchaControlMvc.CaptchaValidator]
public ActionResult Register(Authentication reg, bool captchaValid, string captchaErrorMessage)
{
if (!captchaValid)
ModelState.AddModelError("captcha", captchaErrorMessage);
if (ModelState.IsValid)
{
Registeration register = new Registeration();
var crypto = new SimpleCrypto.PBKDF2();
//string encrypPass = crypto.Compute(reg.Password);
//var length = encrypPass.Length;
register.FirstName = reg.FirstName;
register.LastName = reg.LastName;
register.Email = reg.Email;
register.Password = crypto.Compute(reg.Password);
reg.PasswordSalt = crypto.Salt;
db.Authentications.InsertOnSubmit(reg);
db.SubmitChanges();
}
return View();
}
Any help will be appreciated.Thanks!
Upvotes: 0
Views: 1120
Reputation: 709
You are not storing register in the database, you are storing the original item(reg).
easiset way(least changes would be)
public ActionResult Register(Authentication reg, bool captchaValid, string captchaErrorMessage)
{
if (!captchaValid)
ModelState.AddModelError("captcha", captchaErrorMessage);
if (ModelState.IsValid)
{
var crypto = new SimpleCrypto.PBKDF2();
reg.Password = crypto.Compute(reg.Password);
reg.PasswordSalt = crypto.Salt;
db.Authentications.InsertOnSubmit(reg);
db.SubmitChanges();
}
return View();
}
Upvotes: 2