From cc052298172c999a68ea46cc0e7d7fa900eb8b45 Mon Sep 17 00:00:00 2001 From: Xiao Pan Date: Wed, 28 Feb 2024 05:08:56 -0800 Subject: New script prp, to practice password without print password on-screen --- sh/news | 2 +- sh/prp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100755 sh/prp (limited to 'sh') diff --git a/sh/news b/sh/news index 2896a42..b0ecbc8 100755 --- a/sh/news +++ b/sh/news @@ -17,7 +17,7 @@ daily () { o alacritty --hold -e wtr o alacritty -e newsboat o alacritty --hold -e rate - o alacritty --hold -e pass practice_password2 + o alacritty --hold -e prp } monthly () { diff --git a/sh/prp b/sh/prp new file mode 100755 index 0000000..541b2ee --- /dev/null +++ b/sh/prp @@ -0,0 +1,20 @@ +#!/bin/sh +# PRactice Password + +read_pass () { + stty -echo + # -r necessary because password may contain backslash \ + read -r entered_pass + stty echo +} + +pass_name="${1:-practice_password2}" +correct_pass="$(pass "$pass_name" | { IFS= read -r p; printf %s "$p";})" +echo "Enter password \"$pass_name\":" +read_pass +# `| { IFS= read -r p; printf %s "$p"; }` steal from , GPL-2.0-or-later; I use this because it is much faster than `| head -n1` +while ! [ "$entered_pass" = "$correct_pass" ]; do + echo "Wrong password, enter again:" + read_pass +done +echo "Correct password" -- cgit v1.2.3-70-g09d2