我有使用Bcrpt的问题 [英] I Am Having Issue Using Bcrpt

查看:69
本文介绍了我有使用Bcrpt的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,我下载了Bcrypt用于密码加密,但我在将数据保存到我的数据库并验证密码方面遇到的问题很少..



< pre lang =cs> // 以下代码
字符串 mysalt = BCrypt.GenerateSalt( 12 );
string myharsh = BCrypt.HashPassword(txtpassword.Text,mysalt);
// 现在我想确认我的数据库中是否存在记录
var check =( from c in k .passwordtable 选择 c).FirstOrDefault();
string password = check.passoword;
if (BCrypt.CheckPassword(txtpassword.Text,check)== true
{
lblconfirm = 密码存在;
}
else
{
check.password = myharsh;
k.savechanges();
lblconfirm = 已添加;
}

// 从上面的代码我尝试过使用类似的密码确认,但它无法正常工作,
// 但如果我在没有检查的情况下尝试数据库工作
喜欢这个
if (BCrypt.CheckPassword (txtpassword.Text,myharsh)== true
{
lblconfirm = 密码存在;
}
else
{
lblconfirm = 密码不存在;
}
// 如何从数据库中检索记录并在保存之前确认数据库以避免重复。
// 谢谢,我非常感谢您的时间和精力

解决方案

Good day all, I downloaded Bcrypt for password encryption, but i am having little with issues with saving it on my database and verifying the password..

//Code below
string mysalt = BCrypt.GenerateSalt(12);
           string myharsh = BCrypt.HashPassword(txtpassword.Text, mysalt);
//Now i want to confirm if the record exist on my database
var check = (from c in k.passwordtable select c).FirstOrDefault();
string password = check.passoword;
 if (BCrypt.CheckPassword(txtpassword.Text, check) == true)
{
lblconfirm = "Password Exist";
}
else
{
check.password = myharsh;
k.savechanges();
lblconfirm = "added";
}

//from the code above i have tried using similar password just to confirm, but its not working, 
//but if i try it without checking the database it works
like this
 if (BCrypt.CheckPassword(txtpassword.Text, myharsh) == true)
{
lblconfirm = "Password Exist";
}
else
{
lblconfirm = "Password does not Exist";
}
// how do i retrieve record from the databse and confirm it before saving it to the database to avoid duplicate.
//Thanks, I do appreciate your time and effort

解决方案

这篇关于我有使用Bcrpt的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆