You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
933 B

#!/usr/bin/env bash
# return password to password storage shell
get_password() {
printf 'secret'
}
# initialization value
n=7
# 'hashed' password
hashed_password=168372036536695091
# read password as parameter ...
password=$1
# ... or ask for password
[ -z $1 ] && printf "Enter password:\n" && read -s password
# 'hash' the password with some random multiplications
for (( i=0; i<${#password}; i++ )); do
charval=$(printf "%d\n" \'${password:$i:1}) # ascii value of the current character
n=$(echo "$n * 27 + $charval * 5" | bc) # do some computations and assign to intermediate result
done
# check if hash of entered password is equal to 'hashed' password
if [[ $n -eq $hashed_password ]]; then
# if yes then grant access to prompt
while true; do
printf "\n$(whoami)'s password storage> "
read pass
get_password
done
exit 0
else
# else exit with error code
printf "\nWrong password."
exit 1
fi