Firebird: How to make an md5 hash?

ぐ巨炮叔叔 提交于 2020-01-13 12:00:08

问题


I want to update all passwords in the DB to have a MD5 hashes password. The following doesn't solve my problem:

UPDATE USERS SET USERPASS = hash('SALT' || USERPASS);

Problem being: it returns a hash that was not generated using the MD5 algorithm. How can I impliment the md5 hash algorithm in Firebird?


回答1:


Unfortunately the algortihm of the hash function is not mentioned in the documentation... anyway, you can implement it as an UDF or use some thirdparty UDF lib which implements it. There is a list of UDF Libraries for Firebird on the IBPhoenix website and it seems that both rFunc and FreeAdhocUDF library have one (I only checked these two, there is probably others).




回答2:


The next version of Firebird, Firebird 4, will add cryptographic hash functions. To quote from the Firebird 4 Beta 1 release notes:

Tracker ticket CORE-4436

Returns a hash for a string using a specified algorithm. Format is:

HASH( <string> [ USING <algorithm> ] )    
algorithm ::= { MD5 | SHA1 | SHA256 | SHA512 }

The syntax with the optional USING clause is introduced in FB 4.0 and returns VARCHAR strings in character set OCTETS.

Important

The syntax without the USING clause is still supported. It uses the 64-bit variation of the non-cryptographic PJW hash function (also known as ELF64):
https://en.wikipedia.org/wiki/PJW_hash_function
which is very fast and can be used for general purposes (hash tables, etc), but its collision quality is sub-optimal. Other hash functions (specified explicitly in the USING clause) should be used for more reliable hashing.

Examples

select hash(x using sha256) from y;
-- 
select hash(x) from y; -- not recommended 

Firebird 4 Beta 1 can be downloaded for testing from https://www.firebirdsql.org/en/firebird-4-0-0-beta1/



来源:https://stackoverflow.com/questions/17926695/firebird-how-to-make-an-md5-hash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!