public string ChangePassword(string strpass, string strnewpass, string memberid, string email) { MembersTableAdapters.MembersTableAdapter taMember = new MembersTableAdapters.MembersTableAdapter(); if (taMember.GetDataByMemberID(memberid).Count > 0) { DataRow dtMember = taMember.GetDataByMemberID(memberid).Rows[0]; ValidateLogin valLogin = new ValidateLogin(); if (valLogin.isValid(email, strpass)) { ICryptoService cryptoService = new PBKDF2(); //save this salt to the database string PasswordSalt = cryptoService.GenerateSalt(); //save this hash to the database string hashedPassword = cryptoService.Compute(strnewpass); taMember.UpdatePassword(hashedPassword, PasswordSalt, DateTime.Now, Convert.ToInt32(dtMember["AutoID"])); return "valid"; } else { return "invalid"; } } taMember.Dispose(); return "invalid"; }
protected void btn_newPassword_Click(object sender, EventArgs e) { ICryptoService cryptoService = new PBKDF2(); string password = txtPassword.Text; //save this salt to the database string PasswordSalt = cryptoService.GenerateSalt(); //save this hash to the database string hashedPassword = cryptoService.Compute(password); MembersTableAdapters.MembersTableAdapter taMember = new MembersTableAdapters.MembersTableAdapter(); taMember.UpdatePassword(hashedPassword, PasswordSalt, DateTime.Now, Convert.ToInt32(hfAutoID.Value)); taMember.Dispose(); string strMsg = "<p class=\"header2\">Password Changed</p><p>Now you can login with your new password.</p>"; strMsg += "<p style=\"text-align:right; margin-bottom:1px;\"><input type=button value=\"Log-In Now\" onclick=\"self.location.href='Login.aspx'\"></p><hr>"; litMsgBody.Text = strMsg; }