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

  1. #!/usr/bin/env bash
  2. # return password to password storage shell
  3. get_password() {
  4. printf 'secret'
  5. }
  6. # initialization value
  7. n=7
  8. # 'hashed' password
  9. hashed_password=168372036536695091
  10. # read password as parameter ...
  11. password=$1
  12. # ... or ask for password
  13. [ -z $1 ] && printf "Enter password:\n" && read -s password
  14. # 'hash' the password with some random multiplications
  15. for (( i=0; i<${#password}; i++ )); do
  16. charval=$(printf "%d\n" \'${password:$i:1}) # ascii value of the current character
  17. n=$(echo "$n * 27 + $charval * 5" | bc) # do some computations and assign to intermediate result
  18. done
  19. # check if hash of entered password is equal to 'hashed' password
  20. if [[ $n -eq $hashed_password ]]; then
  21. # if yes then grant access to prompt
  22. while true; do
  23. printf "\n$(whoami)'s password storage> "
  24. read pass
  25. get_password
  26. done
  27. exit 0
  28. else
  29. # else exit with error code
  30. printf "\nWrong password."
  31. exit 1
  32. fi