我想制作一个具有 loginViewController 的 iphone 应用程序。此代码正确且安全吗?
-(IBAction)loginPressed:(id)sender{
NSString *usr = [[NSString alloc]init];
NSString *psw = [[NSString alloc]init];
usr = username.text;
psw = password.text;
NSLog(@"%@",usr);
NSLog(@"%@", psw);
NSString *URL = [NSString stringWithFormat:@"http://www.mywebsite.com/loginApp.php?user_name=%@&password=%@", usr, psw];
NSLog(@"%@", URL);
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:URL]];
NSString *Result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if ([Result isEqualToString:@"1"])
{
NSLog(@"logged in");
}else if ([Result isEqualToString:@"2"]){
UIAlertView *WrongCredential = [[UIAlertView alloc]initWithTitle:@"Loggin failed" message:@"sorry, check again your email and password" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles: nil];
[WrongCredential show];
}
}
登录应用程序.php
<?php
require_once 'functions/init.php';
if (isset($_GET['user_name'], $_GET['password'])){
$email = sanitize($_GET['user_name']);
$password = sanitize($_GET['password']);
$login = loginApp($email, $password);
if($login === true){
echo json_encode(1);
}
else if($login === false){
echo json_encode(2);
}
}
?>
如何检查用户是否已经登录?在php中我可能会设置一个会话/cookies(?),对吧?我如何使用 Objective C 来做到这一点?