iOS 判断用户设置密码是否太简单(如 123,456,111)

- (BOOL)validateLianxu:(NSString *)passWord{
    NSString *last = @"";
    int sub = -1;
    for (int i = 0; i< passWord.length; i++) {
        NSString *str = [passWord substringWithRange:NSMakeRange(i, 1)];
        if ([last isEqualToString:@""]) {
            //第一次进来
            last = str;
            continue;
        }
        if (sub == -1) {
            //第二次进来
            sub = str.integerValue - last.integerValue;
            if (sub>1 ||sub <-1) {
                return NO;
            }
            last = str;
            continue;
        }
        int current_sub = str.integerValue - last.integerValue;
        if (current_sub != sub) {
            return NO;
        }
        last = str;
 
    }
    return YES;
}
posted @ 2016-08-19 18:01  奋斗路上的奋青  阅读(559)  评论(0编辑  收藏  举报