![](/img/trans.png)
[英]How to convert type 'byte[]' to 'System.Data.Linq.Binary'
[英]Cannot implicitly convert type 'string' to 'System.Data.Linq.Binary in LINQ to SQL
我已经对密码进行了哈希处理,然后将其插入数据库,但是这里的问题是每次我尝试执行此查询时都会发生
Cannot implicitly convert type 'string' to 'System.Data.Linq.Binary'
在我数据库accnt_pass的表中是Binary(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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.