密码不匹配 [英] Password did not match
本文介绍了密码不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在db中保存哈希密码和sal密码。
但是当我尝试检索密码时,密码不匹配。为什么。下面是我的代码。
创建用户
Hi All,
I am saving hash password and sal password in db.
But when I trying to retrieve password, the password doesn't match. why. below is my code.
Creating User
protected void Create_User()
{
try
{
string salt = GenerateSalt();
string password = HashPassword(txtpassword.Text, salt);
SqlCommand com = new SqlCommand("Create_User", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@User_Id", txtUserId.Text);
com.Parameters.AddWithValue("@Password", password);
com.Parameters.AddWithValue("@Salt_Password", salt);
com.Parameters.AddWithValue("@Email", txtEmail.Text);
并且在尝试登录时,显示密码不匹配。
请参阅下面的代码
and when trying to login, it shows password did not match.
see code below
protected void Do_Login()
{
SqlCommand com2 = new SqlCommand("select_Salt_Password", con);
com2.CommandType = CommandType.StoredProcedure;
com2.Parameters.Add("@User_Id", SqlDbType.NVarChar, 50).Value = ddl.SelectedItem.Text;
SqlDataAdapter da1 = new SqlDataAdapter(com2);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
string salt = dt1.Rows[0]["Salt_Password"].ToString();
string password = HashPassword(txtPassword.Text, salt);
SqlCommand com11 = new SqlCommand("For_Login1", con);
com11.CommandType = CommandType.StoredProcedure;
com11.Parameters.AddWithValue("@User_Id", ddl.SelectedItem.Text);
com11.Parameters.AddWithValue("@Password", password);
SqlDataAdapter sda = new SqlDataAdapter(com11);
DataTable dtcheck = new DataTable();
sda.Fill(dtcheck);
if (dtcheck.Rows.Count > 0)
{
}
else
{}
和我的sp如下
and my sp as below
ALTER proc [dbo].[For_Login1]
(
@User_Id nvarchar(50),
@Password nvarchar(200)
)
as begin
select * from mtblUser where User_Id=@User_Id and Password=@Password ;
end
但仍然在其他块中。我在哪里弄错了?
谢谢
but still goes in else block. where I am making mistake?
Thanks
推荐答案
首先检查你的GenerateSalt方法,并确保它返回与Do_Login中的代码相同的东西。这里的任何细微差别都意味着非常不同的值。
Start by checking your GenerateSalt method, and make sure it returns the same thing as the code in Do_Login does. Any slight difference here will mean wildly different values.
这篇关于密码不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文