Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql 13 gen_salt not a function

Tags:

postgresql

I am using postgresql v13.2 andlooking to replace importing the bcrypt package with using pgcrypto and 'bf'alogithm.

The attached is using pgAdmin

I get the error ERROR: function gen_salt(unknown) does not exist

The installed pgcrypto version is 1.3

Test table:

CREATE TABLE users (
 id SERIAL PRIMARY KEY,
 email TEXT NOT NULL UNIQUE,
 password TEXT NOT NULL
);

Example code:

INSERT INTO users (email, password) VALUES (
 '[email protected]', 
 crypt('johnspassword', gen_salt('bf'))  
);

Error message: ERROR: function gen_salt(unknown) does not exist LINE 3: crypt('johnspassword', gen_salt('bf')) ); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 95

like image 498
Chris Hunter-Johnson Avatar asked Sep 02 '25 03:09

Chris Hunter-Johnson


1 Answers

You have to enable the crypto function

CREATE TABLE users (
 id SERIAL PRIMARY KEY,
 email TEXT NOT NULL UNIQUE,
 password TEXT NOT NULL
);
INSERT INTO users (email, password) VALUES (
 '[email protected]', 
 crypt('johnspassword', gen_salt('bf'))  
);
ERROR:  function gen_salt(unknown) does not exist

LINE 3: crypt('johnspassword', gen_salt('bf'))
^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.

Run this for every database, you use crypto functions

CREATE EXTENSION pgcrypto;
INSERT INTO users (email, password) VALUES (
 '[email protected]', 
 crypt('johnspassword', gen_salt('bf'))  
);

1 rows affected

db<>fiddle here

like image 107
nbk Avatar answered Sep 04 '25 23:09

nbk