diff options
author | Bruce Momjian <bruce@momjian.us> | 2005-07-25 17:17:41 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2005-07-25 17:17:41 +0000 |
commit | f5df006a04bdaed8ca8e7595bdd5c7c037d65dab (patch) | |
tree | 546e66c8ee0c7d283261761682293877775ddcc9 /src/bin/psql/startup.c | |
parent | 9ad9e694ac19e8e24cc80b84bbcd29a8355ec697 (diff) | |
download | postgresql-f5df006a04bdaed8ca8e7595bdd5c7c037d65dab.tar.gz postgresql-f5df006a04bdaed8ca8e7595bdd5c7c037d65dab.zip |
Add username for psql password prompt, if the username was specified.
Adrian Maier
Diffstat (limited to 'src/bin/psql/startup.c')
-rw-r--r-- | src/bin/psql/startup.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 3f603757c4a..0c3606ed25b 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.119 2005/07/14 08:42:37 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.120 2005/07/25 17:17:41 momjian Exp $ */ #include "postgres_fe.h" @@ -106,6 +106,7 @@ main(int argc, char *argv[]) char *username = NULL; char *password = NULL; + char *password_prompt = NULL; bool need_pass; set_pglocale_pgservice(argv[0], "psql"); @@ -188,8 +189,17 @@ main(int argc, char *argv[]) username = pg_strdup(options.username); } + if (options.username == NULL) + password_prompt = strdup("Password: "); + else + { + password_prompt = malloc(strlen("Password for user %s: ") - 2 + + strlen(options.username) + 1); + sprintf(password_prompt,"Password for user %s: ", options.username); + } + if (pset.getPassword) - password = simple_prompt("Password: ", 100, false); + password = simple_prompt(password_prompt, 100, false); /* loop until we have a password if requested by backend */ do @@ -207,12 +217,13 @@ main(int argc, char *argv[]) need_pass = true; free(password); password = NULL; - password = simple_prompt("Password: ", 100, false); + password = simple_prompt(password_prompt, 100, false); } } while (need_pass); free(username); free(password); + free(password_prompt); if (PQstatus(pset.db) == CONNECTION_BAD) { |