Reputation: 53
Below is the code found on http://www.playframework.com/documentation/1.2.5/secure.
package controllers;
public class Security extends Secure.Security {
static boolean authenticate(String username, String password) {
User user = User.find("byEmail", username).first();
return user != null && user.password.equals(password);
}
}
I want to hardcode the username and password into the controller itself. So that it accepts only those login credentials.
I'm not sure how to do it, but it must be something like this:
package controllers;
public class Security extends Secure.Security {
static boolean authenticate(String username, String password) {
if (username=="[email protected]" && password=="abc123")
return....
.......
}
}
Upvotes: 0
Views: 1641
Reputation: 1465
You are on the right track. However, some notes:
String
equality using the ==
operator. Use String#equals()
instead.String
. These can never be null
and help eliminating NullPointerException
s.username=="[email protected]" && password=="abc123"
is a boolean value, you can simply return that result.Disregarding point 3 about the security issue, your method could look like this:
static boolean authenticate(String username, String password) {
return "[email protected]".equals(username) && "abc123".equals(password);
}
Upvotes: 1