Added input_hidden() to ask for passwords in the CLI without echoing the chars. (0.37.37)
This commit is contained in:
parent
4997ad1e4b
commit
b32f7e839b
7 changed files with 172 additions and 4 deletions
29
examples/input_hidden_example.fun
Executable file
29
examples/input_hidden_example.fun
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Example: Demonstrate hidden input (no echo) for passwords.
|
||||
*
|
||||
* Added: 2026-01-02
|
||||
*/
|
||||
|
||||
#include <io/console.fun>
|
||||
|
||||
print("=== input_hidden() example ===")
|
||||
|
||||
c = Console()
|
||||
|
||||
username = c.ask("Username")
|
||||
password = c.ask_hidden("Password")
|
||||
|
||||
// Do not print the password; just show the username
|
||||
print(join(["Hello, ", username, "!"], ""))
|
||||
|
||||
/* Expected output:
|
||||
Username: hanez
|
||||
Password:
|
||||
=== input_hidden() example ===
|
||||
Hello, hanez!
|
||||
*/
|
||||
45
examples/input_hidden_pam_auth.fun
Executable file
45
examples/input_hidden_pam_auth.fun
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Example: Demonstrate hidden input (no echo) for passwords using
|
||||
* /usr/bin/chkpwd from https://git.xw3.org/hanez/chkusr for PAM authetication.
|
||||
*
|
||||
* Added: 2026-01-02
|
||||
*/
|
||||
|
||||
#include <io/console.fun>
|
||||
|
||||
print("=== input_hidden() example with PAM authentication ===")
|
||||
|
||||
c = Console()
|
||||
|
||||
username = c.ask("Username")
|
||||
password = c.ask_hidden("Password")
|
||||
|
||||
// Do not print the password; just show the username
|
||||
print(join(["Hello, ", username, "!"], ""))
|
||||
|
||||
res = proc_run("chkpwd -u " + username + " -p " + password)
|
||||
content = res["out"]
|
||||
if (res["code"] == 0)
|
||||
print("Login success!")
|
||||
else
|
||||
print("Login failed!")
|
||||
|
||||
/* Possible output:
|
||||
Username: hanez
|
||||
Password:
|
||||
=== input_hidden() example with PAM authentication ===
|
||||
Hello, hanez!
|
||||
Login success!
|
||||
|
||||
Or:
|
||||
Username: hanez
|
||||
Password:
|
||||
=== input_hidden() example with PAM authentication ===
|
||||
Hello, hanez!
|
||||
Login failed!
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue