objective-c 实现用户验证,登陆 Xcode iOS
2012-07-05 16:41
459 查看
- (void)viewDidLoad { [super viewDidLoad]; //加载窗口的时候把从文件里读出用户名。 NSString *filePath = [self documentsPath:@"user.txt"]; //读出文件存到数组username中 NSArray *username = [NSArray arrayWithContentsOfFile:filePath]; self.TXF1.text = [username objectAtIndex:0]; self.Txtpwd.text = [username objectAtIndex:1]; //文本显示设为安全。星号 self.Txtpwd.secureTextEntry = YES; } //登陆验证 - (IBAction)loginpage:(id)sender { NSLog(@"login...\n"); NSString *filePath = [self documentsPath:@"user.txt"]; //从user这个文件里读出用户名和密码是否与输入的相同 NSArray *username = [NSArray arrayWithContentsOfFile:filePath]; if([TXF1.text isEqualToString:[username objectAtIndex:0]] && [Txtpwd.text isEqualToString:[username objectAtIndex:1]]) { //如果验证正确,则重新打开一个窗口 if(self.loginhome ==nil) { NSLog(@"loginhome"); loginhome *homepage = [[loginhome alloc]initWithNibName:@"loginhome" bundle:nil]; self.loginhome = [homepage autorelease]; [self.view addSubview:self.loginhome.view]; } else { [self.view addSubview:self.loginhome.view]; } NSLog(@"登陆成功!\n"); } else { NSLog(@"用户名或密码错误!\n"); judgelogin = [[UIAlertView alloc]initWithTitle:@"提示" message:@"用户名或密码错误!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil]; [judgelogin show]; [judgelogin release]; } } //读程序目录而准备 -(NSString *)bundlePath:(NSString *)fileName { return [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:fileName]; } -(NSString *)documentsPath:(NSString *)fileName { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; return [documentsDirectory stringByAppendingPathComponent:fileName]; } -(NSString *)documentsPath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; return documentsDirectory; }
相关文章推荐
- objective-c 实现用户验证,登陆 Xcode iOS
- Django---用户注册和登陆验证(3)--具体实现--使用默认的
- AJAX+JAVA用户登陆注册验证的实现代码
- Spring从菜鸟到高手(四)(上)使用JdbcTemplate类实现用户登陆验证、批量更新
- 实现session登陆时间的验证,验证用户登录页面的一个监听器
- GoogleReader用户登陆验证C#具体实现
- Spring从菜鸟到高手(四)(上)使用JdbcTemplate类实现用户登陆验证、批量更新
- 基于gin框架和jwt-go中间件实现小程序用户登陆和token验证
- 拦截器实现对用户是否登录及登陆超时的验证
- Laravel框架用户登陆身份验证实现方法详解
- mvc C# JavaScript LigerUI oracle实现用户的注册、登陆验证、登陆
- Struts过滤器实现用户登陆验证
- Spring从菜鸟到高手(四)(上)使用JdbcTemplate类实现用户登陆验证、批量更新
- Hibernate+Struts2+Ajax实现用户登陆验证
- node.js+mysql实现用户登陆验证
- 1_python小程序之实现用户的注册登陆验证功能
- Spring从菜鸟到高手(四)(上)使用JdbcTemplate类实现用户登陆验证、批量更新
- 实现session登陆时间的验证,验证用户登录页面的一个监听器
- 用户登陆与验证的简单实现