【问题标题】:How to impliment captcha varification in iphone sdk如何在 iphone sdk 中实现验证码验证
【发布时间】:2011-08-20 08:50:55
【问题描述】:

我有一项任务要在我的应用程序中使用验证码,它在我的移动应用程序中提供与网站验证码流程相同的验证流程。

我的问题是在我的应用程序中开发或集成验证码。我的漏洞代码是用原生 iphone 语言开发的。我已经搜索了很多验证码在移动应用程序中的集成。但我没有找到任何参考。

所以请帮助我在我的应用程序中开发验证码而不使用 webview。并为其提供一些代码或示例。

【问题讨论】:

  • 您是否注意到 App Store 上的所有应用都没有验证码?有没有想过为什么?
  • 我在 itune 的 1 个应用中看到了验证码。请在生活方式中搜索 DealTiem.ie Mobile。并下载它是免费的。在该发送邮件部分包含验证码。
  • 验证码用于判断用户是人还是机器。在iphone中你不用担心。因为iphone沙箱不允许其他应用程序访问其他应用程序。超过苹果会拒绝应用程序如果您以隐藏方式发送电子邮件。所以这里不需要验证码。

标签: iphone captcha


【解决方案1】:

使用这个 http://iphonesdksnippets.com/post/2009/05/05/Add-text-to-image-%28UIImage%29.aspx 为您的应用找到一个漂亮的背景图片,然后随机生成一些数字和/或文本。 不完全是验证码,但可以解决。 希望对您有所帮助!

【讨论】:

  • 感谢您的回复安德鲁斯。我已经实现了类似的。它作为验证码工作。
  • 链接已过期,请修改您的答案。
【解决方案2】:

虽然不需要在某些应用程序中添加验证码,因为应用程序不像 Web,所以,按照我的想法,不需要在某些应用程序中附加验证码来防止机器人,如果你需要嵌入它... 是的,这是可能的方法,请检查以下代码:

采取这些出口和变量:

NSArray *arrCapElements;
IBOutlet UILabel *Captcha_label;
IBOutlet UITextField *Captcha_field;
IBOutlet UILabel *Status_label;

IBActions 为:

- (IBAction)Reload_Action:(id)sender;
- (IBAction)Submit_Action:(id)sender;

在情节提要中,为 Captcha_label 选择字体名称为 Chalkduster 30.0

现在将arrCapElements 中的viewDidLoad() 分配为

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];
    }
}

会这样显示:

帮助来自:Captcha Generator for iOS

【讨论】:

    猜你喜欢
    • 2012-08-24
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    相关资源
    最近更新 更多