From 40c1e02ff7a0b1c0403e5ee3a23c4d17e7dad0dc Mon Sep 17 00:00:00 2001
From: Andy Lau <liuyang01@kylinos.cn>
Date: Mon, 26 May 2025 15:53:28 +0800
Subject: [PATCH] lib/crypto: Add character echo for password input

Implements character echo (e.g., '*') for user password input in GRUB. Currently,
there is no visual feedback during password entry, making it difficult for users
to confirm their input. This change significantly improves the user experience.

Signed-off-by: Andy Lau <liuyang01@kylinos.cn>
---
 grub-core/lib/crypto.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c
index 396f76410..4506e7c10 100644
--- a/grub-core/lib/crypto.c
+++ b/grub-core/lib/crypto.c
@@ -471,7 +471,10 @@ grub_password_get (char buf[], unsigned buf_size)
       if (key == '\b')
 	{
 	  if (cur_len)
-	    cur_len--;
+        {
+          cur_len--;
+          grub_printf ("\b \b");
+        }
 	  continue;
 	}
 
@@ -479,7 +482,10 @@ grub_password_get (char buf[], unsigned buf_size)
 	continue;
 
       if (cur_len + 2 < buf_size)
-	buf[cur_len++] = key;
+        {
+          buf[cur_len++] = key;
+          grub_printf ("*");
+        }
     }
 
   grub_memset (buf + cur_len, 0, buf_size - cur_len);
-- 
2.34.1

