diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 49d4c0e3ce..fac4b1e87f 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -2023,28 +2023,53 @@ exec_command_password(PsqlScanState scan_state, bool active_branch)
 
 	if (active_branch)
 	{
-		char	   *opt0 = psql_scan_slash_option(scan_state,
+		char	   *user = psql_scan_slash_option(scan_state,
 												  OT_SQLID, NULL, true);
-		char	   *pw1;
-		char	   *pw2;
+		char	   *pw1 = NULL;
+		char	   *pw2 = NULL;
+		PQExpBufferData buf;
 
-		pw1 = simple_prompt("Enter new password: ", false);
-		pw2 = simple_prompt("Enter it again: ", false);
+		initPQExpBuffer(&buf);
 
-		if (strcmp(pw1, pw2) != 0)
+		if (user == NULL)
 		{
-			pg_log_error("Passwords didn't match.");
-			success = false;
+			/* Fetch current user so we can report whose PW will be changed */
+			PGresult   *res;
+
+			res = PSQLexec("SELECT CURRENT_USER");
+			if (!res)
+				success = false;
+			else
+			{
+				user = pg_strdup(PQgetvalue(res, 0, 0));
+				PQclear(res);
+			}
 		}
-		else
-		{
-			char	   *user;
-			char	   *encrypted_password;
 
-			if (opt0)
-				user = opt0;
+		if (success)
+		{
+			printfPQExpBuffer(&buf, _("Enter new password for user \"%s\": "),
+							  user);
+			pw1 = simple_prompt(buf.data, false);
+			if (*pw1 == '\0')
+			{
+				pg_log_error("Empty string is not a valid password.");
+				success = false;
+			}
 			else
-				user = PQuser(pset.db);
+			{
+				pw2 = simple_prompt("Enter it again: ", false);
+				if (strcmp(pw1, pw2) != 0)
+				{
+					pg_log_error("Passwords didn't match.");
+					success = false;
+				}
+			}
+		}
+
+		if (success)
+		{
+			char	   *encrypted_password;
 
 			encrypted_password = PQencryptPasswordConn(pset.db, pw1, user, NULL);
 
@@ -2055,15 +2080,12 @@ exec_command_password(PsqlScanState scan_state, bool active_branch)
 			}
 			else
 			{
-				PQExpBufferData buf;
 				PGresult   *res;
 
-				initPQExpBuffer(&buf);
 				printfPQExpBuffer(&buf, "ALTER USER %s PASSWORD ",
 								  fmtId(user));
 				appendStringLiteralConn(&buf, encrypted_password, pset.db);
 				res = PSQLexec(buf.data);
-				termPQExpBuffer(&buf);
 				if (!res)
 					success = false;
 				else
@@ -2072,10 +2094,13 @@ exec_command_password(PsqlScanState scan_state, bool active_branch)
 			}
 		}
 
-		if (opt0)
-			free(opt0);
-		free(pw1);
-		free(pw2);
+		if (user)
+			free(user);
+		if (pw1)
+			free(pw1);
+		if (pw2)
+			free(pw2);
+		termPQExpBuffer(&buf);
 	}
 	else
 		ignore_slash_options(scan_state);
