开发者

How to set criteria for NHibernate for MySQL MD5?

开发者 https://www.devze.com 2023-03-29 12:47 出处:网络
In MySQL i can do SELECT * FROM table WHERE MD5(column) = \'blablabla\'; But how do i do that with NHibernate and Criteria functions?

In MySQL i can do

SELECT * FROM table WHERE MD5(column) = 'blablabla';

But how do i do that with NHibernate and Criteria functions?

I got a value alrady as md5 but the column in the database is not m开发者_如何学Pythond5 hashed...

I working in C#.

Some ideas?


In Java, you can use Expression.Sql, the same should work in C#, something like:

var table = session.CreateCriteria(typeof(Table))
            .Add(Expression.Sql("MD5(column)= ?", value, NHibernateUtil.String))
            .UniqueResult<Table>();

where value is the hex-encoded value of your MD5 hash.

Although, one word of caution - if the value stored in the database is the user's password, then your design is flawed and insecure. You should only store salted, hashed passwords in the database. No, you shouldn't even do that, you should right away use bcrypt, scrypt or PBKDF2 for that.

0

精彩评论

暂无评论...
验证码 换一张
取 消