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
PostgreSQL offers encryption at several levels, and provides flexibility in protecting data from disclosure due to database server theft, unscrupulous administrators, and insecure networks. Encryption might also be required to secure sensitive data such as medical records or financial transactions.
PostgreSQL database passwords are separate from operating system user passwords. The password for each database user is stored in the pg_authid system catalog. Passwords can be managed with the SQL commands CREATE ROLE and ALTER ROLE, e.g., CREATE ROLE foo WITH LOGIN PASSWORD 'secret' , or the psql command \password .
Transparent Data Encryption, or TDE, is used to secure the data at rest. In other words, it encrypts the data in a database to prevent an attacker from reading the data if they break the first line of defense.
This module implements a data type chkpass that is designed for storing encrypted passwords. Each password is automatically converted to encrypted form upon entry, and is always stored encrypted.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With