Commit 5f17a2e7 authored by Administrator's avatar Administrator

Fixes login check when user does no exists

When an invalid login is provided to the UsersDAO.get method it throws
an IllegalArgumentException. This may happen when the user's credentials
are checked by the LoginFilter, and the exception was not currently
managed. As a result, an user trying to login with an invalid login will
access the main.html page showing an error message.

This commit fixes this error, and invalid user login attempts now return
to the index.html page.
parent 100a9dad
......@@ -4,7 +4,7 @@
<groupId>es.uvigo.esei.daa</groupId>
<artifactId>example</artifactId>
<packaging>war</packaging>
<version>0.1.6</version>
<version>0.1.7</version>
<name>DAA Example</name>
<licenses>
......
......@@ -66,12 +66,16 @@ public class UsersDAO extends DAO {
* @throws DAOException if an error happens while checking the credentials.
*/
public boolean checkLogin(String login, String password) throws DAOException {
final User user = this.get(login);
final String dbPassword = user.getPassword();
final String shaPassword = encodeSha256(SALT + password);
return shaPassword.equals(dbPassword);
try {
final User user = this.get(login);
final String dbPassword = user.getPassword();
final String shaPassword = encodeSha256(SALT + password);
return shaPassword.equals(dbPassword);
} catch (IllegalArgumentException iae) {
return false;
}
}
private final static String encodeSha256(String text) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment