mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Add new psql command \password for changing role password with client-side
password encryption. Also alter createuser command to the same effect.
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.23 2005/12/12 15:48:04 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.24 2005/12/18 02:17:16 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -13,6 +13,7 @@
|
||||
#include "postgres_fe.h"
|
||||
#include "common.h"
|
||||
#include "dumputils.h"
|
||||
#include "libpq/crypt.h"
|
||||
|
||||
|
||||
static void help(const char *progname);
|
||||
@ -246,7 +247,20 @@ main(int argc, char *argv[])
|
||||
if (encrypted == TRI_NO)
|
||||
appendPQExpBuffer(&sql, " UNENCRYPTED");
|
||||
appendPQExpBuffer(&sql, " PASSWORD ");
|
||||
appendStringLiteral(&sql, newpassword, false);
|
||||
|
||||
if (encrypted != TRI_NO)
|
||||
{
|
||||
char encrypted_password[MD5_PASSWD_LEN + 1];
|
||||
|
||||
if (!pg_md5_encrypt(newpassword, newuser, strlen(newuser), encrypted_password))
|
||||
{
|
||||
fprintf(stderr, _("Password encryption failed.\n"));
|
||||
exit(1);
|
||||
}
|
||||
appendStringLiteral(&sql, encrypted_password, false);
|
||||
}
|
||||
else
|
||||
appendStringLiteral(&sql, newpassword, false);
|
||||
}
|
||||
if (superuser == TRI_YES)
|
||||
appendPQExpBuffer(&sql, " SUPERUSER");
|
||||
|
Reference in New Issue
Block a user