无法将类型 'string' 隐式转换为 LINQ 中的 'System.Data.Linq.Binary to SQL



我已经对密码进行了散列处理,然后将其插入数据库,但这里的问题是每次我尝试进行此查询时,都会出现

Cannot implicitly convert type 'string' to 'System.Data.Linq.Binary'

在我数据库的表中,accnt_pass是二进制(50),这是我的代码

//Instantiate a new Hasher Object
var hasher = new Hasher();
hasher.SaltSize = 16;
//Encrypts The password
var encryptedPassword = hasher.Encrypt(txtPass.Text);
Account newUser = new Account();
newUser.accnt_User = txtUser.Text;
newUser.accnt_Position = txtPosition.Text;
newUser.accnt_Pass = encryptedPassword; 

我正在使用Encrypto进行哈希,

如果sql列为二进制类型,则需要将字符串encryptedPassword转换为字节数组。所以不是

newUser.accnt_Pass = encryptedPassword;

放入

System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding();
newUser.accnt_Pass = new System.Data.Linq.Binary(encoding.GetBytes(encryptedPassword));

相关内容

最新更新