Parse case insensitive login - ios

I am using Parse in my Xcode application and when I try to login with:
username: Admin
password: test
it works. But when I enter
username: admin
password: test
the login parameters are invalid. Is there a way to make Parse not case sensitive?

Basically what the link in the comment says is that when you create a new user object or before you let a user login call:
let username = usernameLabel.text
..........................
username = username.lowercaseString
..........................
//Then save the object
So it's not a way to make Parse case-insensitive but it eliminates the need to make it case-insensitive since everything is lowercased.

Some parameters Parse uses are case sensitive so it's up to you to implement the proper methods to rectify this before a user saves any User column properties. After the fact will be too late. So in short, let the user type whatever username they want and save it to the backend as a lowercase string. Then when they re-enter it, translate the user input string into another lowercase string and validate it against the backend (which is now a lower case representation)

Related

Associated domains for automatic strong passwords in iOS with Firebase [duplicate]

My application is linked with firebase database and authentication.
When a user creates an account, the only requirements for the password are for it to be 6 characters. Is there anyway I can make the password more complex, such as make them have a capital letter and a number.
Can I do this from firebase directly, or do I need to do this from my code?
There is no way to configure Firebase Authentication's rules for password strength.
Also see
Password Requirements when making an account with firrebase
Firebase Password Validation allowed regex.
You can (and should ) restrict it from your code. But you can't prevent malicious users from bypassing this by calling the API directly.
If the password strength is a hard requirement for your app, consider implementing custom authentication. This example of custom username (instead of email) and password authentication might be helpful.
Use this function. It includes range 6-15 i.e. minimum 6 and maximum 15 characters.One Capital letter , One number respectively.
func isValidPasswordString(pwdStr:String) -> Bool {
let pwdRegEx = "(?:(?:(?=.*?[0-9])(?=.*?[-!##$%&*ˆ+=_])|(?:(?=.*?[0-9])|(?=.*?[A-Z])|(?=.*?[-!##$%&*ˆ+=_])))|(?=.*?[a-z])(?=.*?[0-9])(?=.*?[-!##$%&*ˆ+=_]))[A-Za-z0-9-!##$%&*ˆ+=_]{6,15}"
let pwdTest = NSPredicate(format:"SELF MATCHES %#", pwdRegEx)
return pwdTest.evaluate(with: pwdStr)
}
This func will return true for valid password string

Firebase and Swift username case-sensitive

When registering a new user, and when I look in the Firebase user database, if the user exists he does not create the accunt, otherwise the registration is completed. But if there is a user named "Tony" in the database and I try to register with the username "tony", Firebase don't understand that "Tony" and "tony" are the same username. I want to solve this.
I state that I wrote the code in swift.
I think the fastest way with querying is to do this:
Duplicate your username list in a new list where all your usernames are lowercased
Lowercase the new username
Check if that username exist in your duplicated list (where all usernames are lowercased)
When it does not exists, append the real username without lowercase to the list with the usernames where they are case-sensitive and to the lowercased username list.
This duplicates data, but it is not that bad since it are only usernames.

How can I use user input to name a child in Firebase?

I'm trying to create a simple user database on Firebase for iOS. I have two textfields, one that takes the user's email address, and the other that takes the user's password. I want the email to be the user's uid. I try to accomplish this by creating a variable called "email" which I set equal to emailTextField.text! Then I implement the code that generates child(s) in Firebase, like so:
ref = Database.database().reference()
ref.child("users").child(email).setValue(true)
Here's my problem: creating a child and naming it using a variable, doesn't work. I can do the following just fine:
ref.child("users").child("email")
but once I take away the quotation marks around "email" so that it becomes the variable, the program crashes.
How can I use user input to name a child in Firebase?
Firebase node / document names do not support the same character set which email addresses support, for example, the . symbol in an email address would make the child name invalid.
If you tried setting a child as
ref.child("users").child("xyz#xyz.xyz")
you should see the same error.
If you absolutely need to use the email address as the node name, I recommend encoding the email in a way which is compatible with the firebase node name rules.
Link to the rules
Edit: If you are using firebase auth, the normal pattern is too use the UID returned by the authenticated user object as the node name, not the email address entered from the textfield.
A quick example:
Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
if let user = user {
ref.child("users").child(user.uid).setValue(true)
}
}

Anonymously login auto generated user

I see that objectId of users generated locally and users created after anonymous login are not the same.
For example
PFUser.enableAutomaticUser()
let localUser = PFUser.currentUser()!.objectId!
print(localUserId) // "obj1"
PFAnonymousUtils.logInWithBlock {
(user: PFUser?, error: NSError?) -> Void in
let annonUserId: String = PFUser.currentUser()!.objectId!
print(annonUserId) // obj2
}
I want that obj1 to persist throughout the anonymous login phase.
Can I somehow "attach" the locally created user and login him anonymously? or is auto generated users are only useful for when you later upgrade him to a user&pass / social based logins ?
PFAnonymousUtils.logInWithBlock is defined to destroy existing anonymous user data and create a new clean anonymous user. You should only do that when the user is logged out.
If you enable anonymous users then one will be created initially and you can add whatever details you want to that. Then, later, when the user wants a real account use signUp: on the PFUser to convert it.
Note that anonymous users aren't real, you can't use them for everything. So, you may have some issues with them actually participating with other users. If this is the case then you may need to create real placeholder users with auto-generated login details and convert that at a later date by updating the username and sending a forgotten password e-mail (or similar).

Use PFUser on Parse without a Username

I'm building an app where emails are supposed to be the main identifiers. I don't want my users to have a username at all. I'm using Parse for backend and want to use the PFUser class for user signups etc. It seems like PFUser requires a username. Is there anyway to use PFUser without using username?
You can set emailAsUsername to true in signUpView as following:
signUpViewController.signUpView.emailAsUsername = true
I am in the same situation as you, but what I do is just set the email address my user enters for the username field. Now they can just login with their email address :)

Resources