在设置注册账号的界面时,经常遇到要求计算用户输入的密码是否过于简单.比如包含数字,字符,字母大小写 中至少两种就算合格.
根据ASCII码的简单计算
- (BOOL)calculatePwdStrength:(NSString*)str{
inta =0;//数字
intb =0;//小写字母
intc =0;//大写字母
intd =0;//字符
for(inti =0; i
if(([strcharacterAtIndex:i]>=48) && ([strcharacterAtIndex:i]<=57)) {
a=1;
}
if(([strcharacterAtIndex:i]>=65) && ([strcharacterAtIndex:i]<=90)) {
b=1;
}
if(([strcharacterAtIndex:i]>=97) && ([strcharacterAtIndex:i]<=122)) {
c=1;
}
if((([strcharacterAtIndex:i]>=33) && ([strcharacterAtIndex:i]<=47))||(([strcharacterAtIndex:i]>=91) && ([strcharacterAtIndex:i]<=96))||(([strcharacterAtIndex:i]>=123) && ([strcharacterAtIndex:i]<=126))) {
d=1;
}
}
if(a+b+c+d >1) {
return1;
}else{
return0;
}
}
这样 调用[self calculatePwdStrength:_newPassword.text] ==0 即可判断出过于简单的密码
网友评论