diff options
author | Joe Conway <mail@joeconway.com> | 2024-01-09 09:16:48 -0500 |
---|---|---|
committer | Joe Conway <mail@joeconway.com> | 2024-01-09 09:16:48 -0500 |
commit | a7be2a6c262d5352756d909b29c419ea5e5fa1d9 (patch) | |
tree | 2219778f27337fc52d44c2ebed13d26def32e025 /doc/src | |
parent | d596736a499858de800cabb241c0107c978f1b95 (diff) | |
download | postgresql-a7be2a6c262d5352756d909b29c419ea5e5fa1d9.tar.gz postgresql-a7be2a6c262d5352756d909b29c419ea5e5fa1d9.zip |
Add new function, PQchangePassword(), to libpq
Essentially this moves the non-interactive part of psql's "\password"
command into an exported client function. The password is not sent to the
server in cleartext because it is "encrypted" (in the case of scram and md5
it is actually hashed, but we have called these encrypted passwords for a
long time now) on the client side. This is good because it ensures the
cleartext password is never known by the server, and therefore won't end up
in logs, pg_stat displays, etc.
In other words, it exists for the same reason as PQencryptPasswordConn(), but
is more convenient as it both builds and runs the "ALTER USER" command for
you. PQchangePassword() uses PQencryptPasswordConn() to do the password
encryption. PQencryptPasswordConn() is passed a NULL for the algorithm
argument, hence encryption is done according to the server's
password_encryption setting.
Also modify the psql client to use the new function. That provides a builtin
test case. Ultimately drivers built on top of libpq should expose this
function and its use should be generally encouraged over doing ALTER USER
directly for password changes.
Author: Joe Conway
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/flat/b75955f7-e8cc-4bbd-817f-ef536bacbe93%40joeconway.com
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/libpq.sgml | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index ed88ac001a1..21195e0e728 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -7116,6 +7116,45 @@ char *PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, </listitem> </varlistentry> + <varlistentry id="libpq-PQchangePassword"> + <term><function>PQchangePassword</function><indexterm><primary>PQchangePassword</primary></indexterm></term> + + <listitem> + <para> + Changes a <productname>PostgreSQL</productname> password. +<synopsis> +PGresult *PQchangePassword(PGconn *conn, const char *user, const char *passwd); +</synopsis> + This function uses <function>PQencryptPasswordConn</function> + to build and execute the command <literal>ALTER USER ... PASSWORD + '...'</literal>, thereby changing the user's password. It exists for + the same reason as <function>PQencryptPasswordConn</function>, but + is more convenient as it both builds and runs the command for you. + <xref linkend="libpq-PQencryptPasswordConn"/> is passed a + <symbol>NULL</symbol> for the algorithm argument, hence encryption is + done according to the server's <xref linkend="guc-password-encryption"/> + setting. + </para> + + <para> + The <parameter>user</parameter> and <parameter>passwd</parameter> arguments + are the SQL name of the target user, and the new cleartext password. + </para> + + <para> + Returns a <structname>PGresult</structname> pointer representing + the result of the <literal>ALTER USER</literal> command, or + a null pointer if the routine failed before issuing any command. + The <xref linkend="libpq-PQresultStatus"/> function should be called + to check the return value for any errors (including the value of a null + pointer, in which case it will return + <symbol>PGRES_FATAL_ERROR</symbol>). Use + <xref linkend="libpq-PQerrorMessage"/> to get more information about + such errors. + </para> + </listitem> + </varlistentry> + <varlistentry id="libpq-PQencryptPassword"> <term><function>PQencryptPassword</function><indexterm><primary>PQencryptPassword</primary></indexterm></term> |