密码不能过于简单的算法

在设置注册账号的界面时,经常遇到要求计算用户输入的密码是否过于简单.比如包含数字,字符,字母大小写 中至少两种就算合格.

根据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 即可判断出过于简单的密码

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容