1. #!/bin/sh
  2. #输入密码
  3. echo "请输入原密码:"
  4. read resultFirst
  5. firstPWD=$resultFirst
  6. echo "请再次输入原密码:"
  7. read resultSecond
  8. secondPWD=$resultSecond
  9. result=""
  10. output=""
  11. function encryptPWD() {
  12. for ((i=0;i<${#firstPWD};i++));do
  13. #获取输入每一个字符并转换为ASCII码
  14. letter=`printf "%d" "'${firstPWD:$i:1}"`
  15. let letter=letter+300
  16. result+=$letter
  17. done
  18. #判断ASCII码长度
  19. if [ ${#result} -lt 10 ];then
  20. output=${result}
  21. echo "您的密码太简单,建议加深密码难度!!!"
  22. else
  23. output=${result:(${#result}-10):${#result}}${result:0:(${#result}-10)}
  24. fi
  25. }
  26. if [ "$firstPWD" = "$secondPWD" ];then
  27. encryptPWD
  28. echo "您的加密后密码为:"
  29. echo $output
  30. else
  31. echo "您两次密码输入不正确!"
  32. fi

http://blog.csdn.net/wenxuechaozhe/article/details/52943852

05-28 09:28