如何验证顺序值的密码?
例如 - 如果用户在密码中输入1326或“axdf”,则该密码有效。
如果使用输入1234或“abcd”则无效。
答案 0 :(得分:9)
我认为你可以这样做
NSString *list= @"abcdefghijklmnopqrstuvwxyz";
NSString *password= @"abz"; // Suppose this is your password
NSRange range = [list rangeOfString:password options:NSCaseInsensitiveSearch];
if (range.location == NSNotFound) {
/* Could NOT find password in list, then it is valid */
}
else {
/* Found the password in the list then it is not valid */
}
同样,您也可以为数字
执行此操作答案 1 :(得分:1)
最简单的方法是使用strpos。
$haystack = '01234567890';
function testConsecutive($pHaystack, $pNeedle){
return strpos($pHaystack,$pNeedle) === false?false:true;
}
哎呀,我以为我在回答php代码,因为那是我的过滤器。这不是php,对不起。
答案 2 :(得分:1)
在这种情况下,我建议您尝试在字符串中匹配ASCII
的{{1}}值。如果字符串是连续的,则该字符的each character
值应增加ASCII
这是一个粗略的想法,你如何实现它,没有测试它,但希望它可能会有所帮助。
1
答案 3 :(得分:0)
字符串是一系列字符,每个字符由ASCII代码表示,因此您可以迭代抛出字符串的字符并将每个字符串与之前的int值进行比较,例如:
- (BOOL)isSequence:(NSString *)string
{
char previousChar = [string characterAtIndex:0];
int wordLength = [string length];
BOOL isSequence = YES;
for (int i = 0; i < wordLength && isSequence; i++)
{
char currentChar = [string characterAtIndex:i];
if (currentChar != previousChar+1) {
isSequence = NO;
}
previousChar = currentChar;
}
return isSequence;
}