[英]Using MySQL PASSWORD() with Entity Framework
We have an old MySQL database that has passwords stored using the MySQL function PASSWORD(). 我们有一个旧的MySQL数据库,该数据库具有使用MySQL函数PASSWORD()存储的密码。 Is there a way using Entity Framework in C# to select the row with the password? 有没有一种方法可以在C#中使用Entity Framework选择带有密码的行?
The old way would be to do a sql query 旧的方法是执行sql查询
SELECT * FROM `employees` WHERE `id` = @id AND `password` = PASSWORD(@pword);
The @id and @pword are then passed to the .Net Connector as parameters. 然后,将@id和@pword作为参数传递给.Net连接器。
In Entity we do this 在实体中,我们这样做
var query = from employeeRow in context.employees
where employeeRow.id.Equals(username_txt.Text)
select employeeRow;
_foundEmployee = query.SingleOrDefault();
But this will return the row data without checking the password. 但这将返回行数据,而不检查密码。 How would I check the password that has been hashed with MySQL PASSWORD()? 我如何检查已用MySQL PASSWORD()散列的密码?
where employeeRow.id.Equals(username_txt.Text) && employeeRow.password.Equals(hashedPassword)
You need to do password hashing separately. 您需要单独进行密码哈希处理。 I'd suspect mysql documentation will tell you what algorithm PASSWORD() method uses. 我怀疑mysql文档会告诉您PASSWORD()方法使用什么算法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.