这是ZXCVBN在Obj-C中的密码强度估算。
ZXCVBN的原始版本是一个CoffeeScript版本。但这段代码基于Ryan Pearl的Python版本。tools/中的JSON生成器也来自于Python版本。
关于zxcvbn的详细信息和背后的动机,请参阅Dropbox博客文章。
CocoaPods 是Objective-C的依赖管理器,它自动并简化了在项目中使用第三方库的过程。
platform :ios, '7.0'
pod "ZXCVBN"
#import <ZXCVBN/BBPasswordStrength.h>
BBPasswordStrength *strength = [[BBPasswordStrength alloc] initWithPassword:@""];
[strength score]; // 0
[strength entropy]; // 0.0
[strength scoreLabel]; // Very Weak
[strength crackTimeDisplay]; // no time
BBPasswordStrength *strength = [[BBPasswordStrength alloc] initWithPassword:@"zxcvbn"];
[strength score]; // 0
[strength entropy]; // 6.845
[strength scoreLabel]; // Very Weak
[strength crackTimeDisplay]; // no time
BBPasswordStrength *strength = [[BBPasswordStrength alloc] initWithPassword:@"qwER43@!"];
[strength score]; // 1
[strength entropy]; // 26.44
[strength scoreLabel]; // Weak
[strength crackTimeDisplay]; // 39 minutes
BBPasswordStrength *strength = [[BBPasswordStrength alloc] initWithPassword:@"Tr0ub4dour&3"];
[strength score]; // 2
[strength entropy]; // 30.435
[strength scoreLabel]; // So-so
[strength crackTimeDisplay]; // 11 hours
BBPasswordStrength *strength = [[BBPasswordStrength alloc] initWithPassword:@"correcthorsebatterystaple"];
[strength score]; // 4
[strength entropy]; // 45.212
[strength scoreLabel]; // Great!
[strength crackTimeDisplay]; // 64 years