- #!/bin/sh
- #输入密码
- echo "请输入原密码:"
- read resultFirst
- firstPWD=$resultFirst
- echo "请再次输入原密码:"
- read resultSecond
- secondPWD=$resultSecond
- result=""
- output=""
- function encryptPWD() {
- for ((i=0;i<${#firstPWD};i++));do
- #获取输入每一个字符并转换为ASCII码
- letter=`printf "%d" "'${firstPWD:$i:1}"`
- let letter=letter+300
- result+=$letter
- done
- #判断ASCII码长度
- if [ ${#result} -lt 10 ];then
- output=${result}
- echo "您的密码太简单,建议加深密码难度!!!"
- else
- output=${result:(${#result}-10):${#result}}${result:0:(${#result}-10)}
- fi
- }
- if [ "$firstPWD" = "$secondPWD" ];then
- encryptPWD
- echo "您的加密后密码为:"
- echo $output
- else
- echo "您两次密码输入不正确!"
- fi
http://blog.csdn.net/wenxuechaozhe/article/details/52943852