iOS add pinpad to secure the app - ios

I'm building an iPad app in where I need to implement a pin secure lock screen.
I have created a very simple hardcoded password 1234, see below:
- (IBAction)enterPassword
{
NSString *passwordString = [NSString stringWithFormat:#"1234"];
if ([passwordField.text isEqualToString:passwordString]) {
//hide password field
passwordField.hidden = YES;
//show main application view
[super viewDidLoad];
}
else {
// Password is incorrect
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Incorrect Password" message:#"This password is incorrect." delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
[alert show];
}
}
Now, how can I implement an ability for user to change the password anytime they want to, so that they are not depended on the hardcoded password.
Also, when they are about to change the password they will be asked for the current old password in order to change it.
Please bare in mind that I'm a very new in iOS developing :(
Many thanks for your help.

Related

iOS - HomeKit: why it takes too long to add a user?

I am trying to add a user (HMUser) to my home (HMHome) by
[self.home addUserWithCompletionHandler:^(HMUser *user, NSError *error) {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
return;
}
NSLog(#"add done!");
[weakSelf.tableView reloadData];
}];
as referenced from: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/HomeKitDeveloperGuide/ManagingUsers/ManagingUsers.html
From my phone (whose iCloud email is: me#gmail.com for e.g.), I add a guest (whose iCloud email is: guest#gmail.com for e.g.). Immediately, the guest receives a notification from Apple and has to press Accept, as expected. After that, my app can display the guest email, which is correct. The issue is: the guest is very hard to view my shared home. Sometimes I have to wait ~ 2 hours but the guest still cannot view my home layout. I tried to reset wifi/bluetooth on the guest phone but things are not better.
Do you have any ideas about this issue on how to fix it?
Thanks in advance,

Touch ID for login iOS

I'm making an iOS application (Obj-c) with a login form. I'm trying to figure out if there is a way to use Touch ID to login. This will be an amazing feature for my app, but I can't find a way to do it.
In the last PayPal update they include the Touch ID login - so there is a way to do it.
EDIT: I know how to get if the user enter the correct Touch ID, but I don't know what to do after that.
What if the user enter his username and then add the Touch ID correctly? How could I know this user have this Touch ID?
Okay first create an action like so:
We need more detail tough, as I do not know if you mean Obj-C or swift, I'll just post both.
Obj-C
Firstly import the local authentication framework
#import <LocalAuthentication/LocalAuthentication.h>
Then we create an IBAction and add the following code:
- (IBAction)authenticateButtonTapped:(id)sender {
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:#"Are you the device owner?"
reply:^(BOOL success, NSError *error) {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"There was a problem verifying your identity."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
return;
}
if (success) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"You are the device owner!"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"You are not the device owner."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
}];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Your device cannot authenticate using TouchID."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
}
The just connect your IBAction to a button that will prompt authentication.
However in Swift you would use:
Add the following framework to your project: LocalAuthentication
Then import it in your swift file:
import LocalAuthentication
Then create the following method that will prompt you to use touch id:
func authenticateUser() {
// Get the local authentication context.
let context = LAContext()
// Declare a NSError variable.
var error: NSError?
// Set the reason string that will appear on the authentication alert.
var reasonString = "Authentication is needed to access your notes."
// Check if the device can evaluate the policy.
if context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &error) {
[context .evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reasonString, reply: { (success: Bool, evalPolicyError: NSError?) -> Void in
if success {
}
else{
// If authentication failed then show a message to the console with a short description.
// In case that the error is a user fallback, then show the password alert view.
println(evalPolicyError?.localizedDescription)
switch evalPolicyError!.code {
case LAError.SystemCancel.rawValue():
println("Authentication was cancelled by the system")
case LAError.UserCancel.rawValue():
println("Authentication was cancelled by the user")
case LAError.UserFallback.rawValue():
println("User selected to enter custom password")
self.showPasswordAlert()
default:
println("Authentication failed")
self.showPasswordAlert()
}
}
})]
}
else{
// If the security policy cannot be evaluated then show a short message depending on the error.
switch error!.code{
case LAError.TouchIDNotEnrolled.rawValue():
println("TouchID is not enrolled")
case LAError.PasscodeNotSet.rawValue():
println("A passcode has not been set")
default:
// The LAError.TouchIDNotAvailable case.
println("TouchID not available")
}
// Optionally the error description can be displayed on the console.
println(error?.localizedDescription)
// Show the custom alert view to allow users to enter the password.
self.showPasswordAlert()
}
}
Lastly from the func viewDidLoad call the function like so: authenticateUser()
Hope that helps. Keep coding.
Sources:
Swift:
App Coda iOS 8 Touch ID Api
Objective-C:
tutPlus iOS Touch ID
Thanks to Matt Logan for the updated swift code.
I think I understand what I have to do!
After the first user Login I'll save his password (at NSUserdefaults for example).
If the user want to use his Touch ID at the next login - I'll ask him for the Touch ID and if it's correct i'll let him in with the password saved at the beginning.
Thanks to Julian :)

Forgot Password code: Objective C

I'm building an iOS app and I need to provide a forgot password function. I have a db that stores registered users and their details(userArray). I have searched by email inputed so, how do I do a UIAlert that shows the found password??? below is code I tried but my if condition is wrong.
[self.theuser valueForKey:#"password"] is the retrieved password from the database and its a string.
- (IBAction)ForgotPassword:(id)sender {
if ([[self.theuser valueForKey:#"password"] > 0 ]) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Success"
message: #"Your Password is:"
delegate: self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
You need to check that the length of the string is higher than 0, because using this:
if ([self.theuser valueForKey:#"password"])
will always return true if the value is other than nil, meaning if you server code returns that the value of password is "" (two quote marks with no space in between) then the app will recognize that the value is not nil and display an alert with no text in it
So the final code should look something like this:
- (IBAction)ForgotPassword:(id)sender {
NSString *retrievedPassword = [self.theuser valueForKey:#"password"];
if ( retrievedPassword.length > 0) {
NSString *message = [NSString stringWithFormat:#"Your password is: %#", retrievedPassword];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Success"
message: message
delegate: self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
}
Change:
#"Your Password is:"
to:
[NSString stringWithFormat:#"Your Password is: %#", [self.theuser valueForKey:#"password"]]
You can also change this:
if ([[self.theuser valueForKey:#"password"] > 0 ]) {
to this:
if ([self.theuser valueForKey:#"password"]) {
If it didn't exist, it would count as "false". Any other value is "true".

Objective-c - validate filled fields before publish item

In my application I send data to server and parse.
But I have to send image and you need to choose category.
When you don't choose category I show for user information.
But: how can I check if the user has filled in all the fields? In my app choose image and category?
This is my code with show error when you don't choose category and send action:
- (IBAction)submitItem:(UIButton *)sender {
if ([category isEqualToString:#""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Category 'All' is reserved" message:#"You need to choose different category" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
return;
}
NSData *imageData = UIImageJPEGRepresentation(imageView.image, 1.0);
///// send image to server
NSString *urlString = urlSaveFullImageToServer;
Your change could be as simple as using an else statement...
- (IBAction)submitItem:(UIButton *)sender {
if ([category isEqualToString:#""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Category 'All' is reserved" message:#"You need to choose different category" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
return;
}
else {
NSData *imageData = UIImageJPEGRepresentation(imageView.image, 1.0);
///// send image to server
NSString *urlString = urlSaveFullImageToServer;
...
Personally I think a better approach is not to enable the "send" button until all of the data is complete.
Set the submit button enabled property to NO and then when the various pieces of information are entered (the image, the category) check to see if everything is complete - once it is, set enabled to YES

Parse - Sign Up and Login at the same time

Using Parse (iOS framework), I am able to sign up and login successfully using two API.
When user log in, it will cache the user and so accessing "currentUser" will return appropriate object. But sign up API is not caching.
Is there any way that sign up itself will cache the user and avoid separate log in functionality?
It should automatically log you in as well. For example, if in your completion block in signUpInBackground, you have a segue to your main screen and in your main screen, it is supposed to show information related to the user, then it will because [PFUser currentUser] is set to the user that registered.
here is an example
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[[error userInfo] objectForKey:#"error"] message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
[alertView show];
// Bring the keyboard back up, because they'll probably need to change something.
[_usernameField becomeFirstResponder];
}
else{
// Success!
[self performSegueWithIdentifier:#"goToMain" sender:self];
}
}];

Resources