How do I encrypt passwords with PostgreSQL?

前端 未结 2 1175
陌清茗
陌清茗 2021-01-31 20:48

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(byte         


        
2条回答
  •  生来不讨喜
    2021-01-31 21:35

    digest(data text, type text) returns bytea; is not valid syntax.

    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'));
    

    Later...

    UPDATE table SET password = crypt('password',gen_salt('bf'))
    

    And checking the password:

    SELECT ... FROM table 
        WHERE password is NOT NULL 
          AND password = crypt('password-to-test',password);
    

    Bcrypt is recommended by Crafted Software and Jeff Atwood. The official pgcrypto docs may also be of interest.

提交回复
热议问题