I need to verify user password, but this user may be "local" (with md5
method in pg_hba.conf
) or LDAP user. This works fine and "local" and LDAP users can login, but I need to verify their password in PL/PGSQL in some function. Is it possible? To call some Postgres system function like verify_login(userName TEXT, userPassword TEXT)
which returns BOOLEAN
and it knows how to check the password of the user when it is local/LDAP/etc. user.
PS. Little bit strange idea, but it's the requirement of my task.
Best Answer
I did it as:
Specific things are replaced with
...
- they are not related to the question. To use it you needCREATE EXTENSION IF NOT EXISTS dblink;
to enable thedblink
extension.This
login()
function verifies the password of the user by connecting to itself (to the current host (ifdbhost
isNULL
) and to the current database.It was tested and I use it but it works fine only if the host has just one IP. Otherwise, it's not clean which IP will be returned from the
INET_SERVER_ADDR()
.