2013-08-22 88 views
0

我已經使用下面的代碼進行用戶註冊。當我調試密碼是加密形式,但它存儲爲純文本。密碼鹽也已存儲在數據庫。加密密碼不是保存在數據庫,但只有鹽密碼

[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(); 
    } 

任何幫助將不勝感激。謝謝!

+1

'register'被添加或保存到數據庫的位置?看來你是爲'reg'做的。 –

+0

如何將註冊添加到數據庫? – Wasfa

回答

2

您沒有在數據庫中存儲註冊,您正在存儲原始項目(reg)。

easiset方式(至少改變會)

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(); 
} 
+0

如何將註冊存儲到數據庫? – Wasfa

+0

更新了我的答案 –