I'm using PostgreSQL 9.5 and trying to comprehend how to store passwords with digest and crypt functions within the pgcrypto module. I have a table like this:
CREATE TABLE "usuarios" (
"id" integer NOT NULL ,
"password" varchar(120),
CONSTRAINT usuarios_pk PRIMARY KEY ("id")
);
I succesfully saved the first row with this query:
INSERT INTO public.usuarios VALUES (DEFAULT,digest('somesalt' || 'mypass','sha256'));
I took the idea of the global salt and the digest using the sha256 algorithm reading this post and the official documentation following the example using crypt()
My problem is, when I try to compare the password in pgAdmin with the following query:
SELECT (usuarios.password = digest('somesalt' || 'mypass','sha256')) AS Match FROM usuarios;
I get an error mismatching password type( varchar) and digest type (bytea). I have been looking around for a workaround or how the cast would be but cannot find it or, maybe cannot understand what's under my nose. Any help?