如何在iphonesdk中实现验证码变体
我的应用程序中有一项使用验证码的任务,它在我的移动应用程序中提供了与网站验证码过程相同的验证过程 我的问题是在我的应用程序中开发或集成验证码。我的洞代码是用本地iphone语言开发的。我在移动应用程序中搜索了很多验证码的集成。但我没有找到任何参考资料 因此,请帮助我在不使用webview的情况下在我的应用程序中开发captcha。并提供一些代码或示例。使用此 为你的应用程序找到一张漂亮的背景图片,然后随机生成一些数字和/或文本。 不完全是验证码,但它可以解决问题。如何在iphonesdk中实现验证码变体,iphone,captcha,Iphone,Captcha,我的应用程序中有一项使用验证码的任务,它在我的移动应用程序中提供了与网站验证码过程相同的验证过程 我的问题是在我的应用程序中开发或集成验证码。我的洞代码是用本地iphone语言开发的。我在移动应用程序中搜索了很多验证码的集成。但我没有找到任何参考资料 因此,请帮助我在不使用webview的情况下在我的应用程序中开发captcha。并提供一些代码或示例。使用此 为你的应用程序找到一张漂亮的背景图片,然后随机生成一些数字和/或文本。 不完全是验证码,但它可以解决问题。 希望有帮助 虽然在某些应用程序
希望有帮助 虽然在某些应用程序中不需要添加验证码,因为应用程序不像Web,因此,根据我的想法,在某些应用程序中不需要附加验证码来防止僵尸程序,但如果需要嵌入验证码。。。 是的,这是可能的方法,请检查以下代码: 以这些出口和变量为例:
NSArray *arrCapElements;
IBOutlet UILabel *Captcha_label;
IBOutlet UITextField *Captcha_field;
IBOutlet UILabel *Status_label;
和iActions
作为:
- (IBAction)Reload_Action:(id)sender;
- (IBAction)Submit_Action:(id)sender;
在情节提要中,为验证码标签选择字体名为Chalkduster 30.0
现在将viewDidLoad()
中的arrCapElements
分配为
arrCapElements = [[NSArray alloc]initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z",@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z", nil];
加载验证码的代码:
-(void)load_captcha{
@try {
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
Captcha_label.backgroundColor = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
//Captcha_label.textColor=[UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
NSUInteger elmt1,elmt2,elmt3,elmt4,elmt5,elmt6;
elmt1 = arc4random() % [arrCapElements count];
elmt2= arc4random() % [arrCapElements count];
elmt3 = arc4random() % [arrCapElements count];
elmt4 = arc4random() % [arrCapElements count];
elmt5 = arc4random() % [arrCapElements count];
elmt6 = arc4random() % [arrCapElements count];
NSString *Captcha_string = [NSString stringWithFormat:@"%@%@%@%@%@%@",arrCapElements[elmt1-1],arrCapElements[elmt2-1],arrCapElements[elmt3-1],arrCapElements[elmt4-1],arrCapElements[elmt5-1],arrCapElements[elmt6-1]];
//NSLog(@" Captcha String : %@",Captcha_string);
Captcha_label.text = Captcha_string;
}
@catch (NSException *exception) {
NSLog(@"%@",exception);
}
}
重新加载操作:
- (IBAction)Reload_Action:(id)sender {
[self load_captcha];
}
检查验证码是否正确:
- (IBAction)Submit_Action:(id)sender {
NSLog(@"%@ = %@",Captcha_label.text,Captcha_field.text);
if([Captcha_label.text isEqualToString: Captcha_field.text]){
[self.view endEditing:YES];
Status_label.text =@"Success";
Status_label.textColor = [UIColor greenColor];
}else{
Status_label.text =@"Faild";
Status_label.textColor = [UIColor redColor];
}
}
它将显示如下:
帮助摘自:您是否注意到应用商店中的所有应用都没有验证码?有没有想过为什么?我在iTunes的1个应用程序中看到过验证码。请在生活方式中搜索DealTiem.ie Mobile。并下载它是免费的。在“发送邮件”部分包含验证码。验证码用于确定用户是人还是机器。在iphone中,你不用担心。因为iphone沙盒不允许其他应用程序访问其他应用程序。如果你以隐藏方式发送电子邮件,苹果将拒绝应用程序。因此,此处不需要验证码。可能重复感谢你的回答安德鲁斯。我已经实现了同样的功能。该链接已过期,请修改您的答案。