summaryrefslogtreecommitdiff
path: root/src/bin/scripts/createuser.c
diff options
context:
space:
mode:
authorPeter Eisentraut2005-12-18 02:17:16 +0000
committerPeter Eisentraut2005-12-18 02:17:16 +0000
commit9828a76edcc45c5958780b9d2c0e6a0961845ab7 (patch)
treebf8634c21c8b9ea97a13b2c1b3ddac3fda6ab0b3 /src/bin/scripts/createuser.c
parentf8331b68a6c8db92caa0ed3d1ecb02205e40738f (diff)
Add new psql command \password for changing role password with client-side
password encryption. Also alter createuser command to the same effect.
Diffstat (limited to 'src/bin/scripts/createuser.c')
-rw-r--r--src/bin/scripts/createuser.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c
index e784bb6ae5..51b8dad931 100644
--- a/src/bin/scripts/createuser.c
+++ b/src/bin/scripts/createuser.c
@@ -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");