Currently I am attempting to use wp_check_password
to simply return 1
or 0
to represent if the login worked. However whenever I attempt to require_once
‘wp-blog-header.php’ or any other php file the result is:
Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: not found (404)" UserInfo=0xf6c4720 {NSErrorFailingURLKey=http://www.**{site}**.com/BBT/appLogin.php, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xf6a5a40> { URL: http://www.**{site}**.com/BBT/appLogin.php } { status code: 404, headers {
"Cache-Control" = "no-cache, must-revalidate, max-age=0";
Connection = close;
"Content-Encoding" = gzip;
"Content-Length" = 21;
"Content-Type" = "text/html; charset=UTF-8";
Date = "Sat, 05 Apr 2014 15:37:26 GMT";
Expires = "Wed, 11 Jan 1984 05:00:00 GMT";
Pragma = "no-cache";
Server = "Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.0-fips mod_bwlimited/1.4";
Vary = "Accept-Encoding,User-Agent";
"X-Pingback" = "http://www.**{site}**.com/wp/xmlrpc.php";
"X-Powered-By" = "PHP/5.3.26";} }, NSLocalizedDescription=Request failed: not found (404)}
My xcode function is:
-(void) submitLogin {
//check information online either show alert or seque to management.
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Info"
message:@""
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager manager] initWithBaseURL:[self.globalVars appBaseStringAsURL]];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
NSDictionary *params = @{@"username": self.usernameTextField.text,
@"password": self.passwordTextField.text};
[manager POST:[self.globalVars appLoginString] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@",[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
BOOL success = [[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] boolValue];
if (success) {
[self performSegueWithIdentifier:@"toEventManagement" sender:self];
} else {
[message setMessage:[NSString stringWithFormat:@"Incorrect login information"]];
[message show];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
[message setMessage:[NSString stringWithFormat:@"Error connecting to server"]];
[message show];
}];
}
My php code is:
<?php
$username = $password = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
require_once('../wp/wp-blog-header.php');
$username = clean_data($_POST['username']);
$password = clean_data($_POST['password']);
$user = get_user_by('login',$username);
if ( $user and wp_check_password($password, $user->data->user_pass, $user->ID) ){
echo 1;
} else {
echo 0;
}
}
?>
or of course if anyone could guide me to a better way to get this done, I would greatly appreciate it.
EDIT: in the mean time I’ll just use an async NSURLConnection
did you try require_once ‘wp-load.php’ instead? Thats what worked for me. I also tried wp-blog-header.php and got the same error. wp-load.php seems to work.