简体   繁体   中英

MobileFirst User authentication security check with database

I am following this tutorial:

http://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/authentication-and-security/user-authentication/security-check/

There they check the credentials, that they have received from the user's input in the app:

@Override
protected boolean validateCredentials(Map<String, Object> credentials) {
    if(credentials!=null && credentials.containsKey("username") && credentials.containsKey("password")){
        String username = credentials.get("username").toString();
        String password = credentials.get("password").toString();
        if(!username.isEmpty() && !password.isEmpty() && username.equals(password)) {
            return true;
        }
    }
    return false;
}

As you can see, the authentication returns true when username and password are equal. I have a mysql databse, where I have saved the registered users. So I want to check the entered credentials against the data in my database. How do I have to change the adapter and the method so I can do this?

To achieve this , you will need to write the code to connect to your DB, invoke the SQL query to check the data in DB.

Within your security check's validateCredentials method, you should write the code to connect to your DB that holds the registered user information. Check for the user details against the DB and based on the outcome , return true of false.

A sample Java SQL adapter is listed here . You can use it for your reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM