本文介绍了如何使用PostgreSQL加密密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在编码密码时遇到一些问题,该怎么办。编码类型md5
I have some problems with encoding passwords,how can I do it. Type of encoding md5
digest(data text, type text) returns bytea;
CREATE OR REPLACE FUNCTION md(bytea) returns text AS $$
SELECT encode(digest($1, 'sha1'), 'md5')
$$ LANGUAGE SQL STRICT IMMUTABLE;
INSERT INTO "login"(login, password, employee_id)
VALUES ( 'email',crypt('password', md('md5')), 1);
*** 错误 ** *
*** Error ***
ERROR: syntax error at or near "digest"
SQL state: 42601
Character: 1
推荐答案
digest(数据文本,键入文本)返回bytea;
无效的语法。
我建议改为使用 bcrypt
。不需要其他功能定义:
I recommend using bcrypt
instead. No additional function definitions are required:
INSERT into "login" (login, password, employee_id)
VALUES ('email',crypt('password', gen_salt('bf'));
后来...
UPDATE table SET password = crypt('password',gen_salt('bf'))
并检查密码:
SELECT ... FROM table
WHERE password is NOT NULL
AND password = crypt('password-to-test',password);
Bcrypt由和可能也很有趣。
Bcrypt is recommended by Crafted Software and Jeff Atwood. The official pgcrypto docs may also be of interest.
这篇关于如何使用PostgreSQL加密密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!