您好我有这种情况我正在使用以下代码添加用户名和加密密码的用户
public string Encrypt(string str)
{
string EncrptKey = "2015;[xzyLIT)key";
byte[] byKey = { };
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
byKey = System.Text.Encoding.UTF8.GetBytes(EncrptKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(str);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
我将带有加密密码的用户添加到数据库
之后我尝试登录时出现问题
没有数字和符号的密码在数据库中生成相同的加密密码,并且我成功登录
使用以下代码
public string Encrypt(string str)
{
string EncrptKey = "2015;[xzyLIT)key";
byte[] byKey = { };
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
byKey = System.Text.Encoding.UTF8.GetBytes(EncrptKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(str);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
protected void txtlog_Click(object sender, EventArgs e)
{
string pass = Encrypt(txtpas.Text).ToString();
UsersClass u = new UsersClass();
if (u.Login(txtuser.Text, pass) == true)
{
UtilityClass.CreateCookie("login", new string[] { "username", "usertypeid" }, new string[] { txtuser.Text, u.UserTypeID.ToString().Trim() }, !chkrem.Checked, Response);
Response.Redirect("SiteAdmin/index.aspx");
}
else
{
Label1.Text = "“Invalid Username or Password”";
}
}
当我输入密码包含数字时出现问题,例如:pass123或符号示例:将@ 123传递给数据库。
当我尝试登录时出现错误“无效的用户名或密码” 我跟踪代码我发现输入密码时的加密值与数据库中排序的值不同有什么问题?