我想製作一個具有loginViewController的iphone應用程序。這個代碼是否正確和安全?IOS登錄 - 此代碼是否正確/安全?我如何檢查用戶是否已經登錄?
-(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];
}
}
loginApp.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做到這一點?
感謝您的建議。 +1 – mat 2013-03-19 15:27:32
這個答案與應用程序範圍有限有關。如果即使在應用程序關閉後仍想保留該信息,則使用NSUserDefaults存儲該值 - 這是保存單個值(最小數據)的更好選擇。您可以通過網絡輕鬆獲取有關NSUserDefaults的教程。 – Mrunal 2013-03-19 16:39:10