Last active 1 year ago

needs nerdfont & secret service entry with account = $account_value

mxywes revised this gist 1 year ago. Go to revision

No changes

mxywes revised this gist 1 year ago. Go to revision

1 file changed, 1 insertion, 1 deletion

example.md

Diff is too large to be shown

mxywes revised this gist 1 year ago. Go to revision

2 files changed, 1 insertion, 1 deletion

example.md(file created)

Diff is too large to be shown

example.png (file deleted)

Diff is too large to be shown

mxywes revised this gist 1 year ago. Go to revision

1 file changed, 1 insertion

example.png(file created)

Diff is too large to be shown

mxywes revised this gist 1 year ago. Go to revision

1 file changed, 57 insertions

learn_pass.sh(file created)

@@ -0,0 +1,57 @@
1 + #!/bin/bash
2 + # Secret service entry needs the account key set to:
3 + account_value=learning_password
4 +
5 +
6 + # Function to check the input against the stored secret
7 + check_secret() {
8 + local input="$1"
9 + local secret_service_account="$2"
10 +
11 + local secret
12 + secret=$(secret-tool lookup account "$secret_service_account")
13 +
14 + if [[ $? -ne 0 || -z "$secret" ]]; then
15 + echo -e "\033[31mError: Could not retrieve secret.\033[0m"
16 + return 1
17 + fi
18 +
19 + local result=""
20 + for ((i = 0; i < ${#input}; i++)); do
21 + if [[ "${input:$i:1}" == "${secret:$i:1}" ]]; then
22 + result+="\033[32m\033[0m" # Green for correct
23 + else
24 + result+="\033[31m\033[0m" # Red for incorrect
25 + fi
26 + done
27 +
28 + local len_string=""
29 + if [[ ${#input} -gt ${#secret} ]]; then
30 + len_string="\033[33m+$((${#input} - ${#secret}))\033[0m"
31 + elif [[ ${#input} -lt ${#secret} ]]; then
32 + len_string="\033[33m-$((${#secret} - ${#input}))\033[0m"
33 + else
34 + len_string="\033[32m==\033[0m"
35 + fi
36 +
37 + echo -e "Result ($len_string): $result"
38 + return 0
39 + }
40 +
41 + while true; do
42 + echo -n "Enter secret (hidden input, Ctrl+C to exit): "
43 + input=""
44 +
45 + while IFS= read -rsn1 char; do
46 + if [[ "$char" == "" ]]; then # Enter key
47 + echo
48 + break
49 + fi
50 + echo -n ""
51 + input+="$char"
52 + done
53 +
54 + check_secret "$input" "$account_value"
55 +
56 + echo
57 + done
Newer Older