summaryrefslogtreecommitdiff
path: root/src/bin/scripts/createuser.c
diff options
context:
space:
mode:
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");