Get Password (securely)


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/bin/sh
  2.  
  3. # Demonstrate reading passwords in a shell script
  4. # while not echoing those passwords to the screen.
  5.  
  6. # Note `read -s` in bash 3 at least does not echo
  7. # the return/newline either? Therefore we need to
  8. # `echo >&2` after each read to simulate that.
  9.  
  10. getpassword()
  11. {
  12. until [ "$password" = "$rpassword" -a -n "$password" ]; do
  13. read -s -p "Enter a password for user '$1' : " password; echo >&2
  14. read -s -p "Reenter password for user '$1' : " rpassword; echo >&2
  15. done
  16. echo "$password"
  17. }
  18.  
  19. pw=`getpassword "${1:-blah}"`
  20.  
  21. echo "password is '$pw'"

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.