Revize 90348e15
Přidáno uživatelem Jiri Trefil před asi 2 roky(ů)
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpl.java | ||
---|---|---|
111 | 111 |
*/ |
112 | 112 |
@Override |
113 | 113 |
public UserModelStatusCodes loginUser(User user) { |
114 |
final String name = user.getName(); |
|
115 |
final String password = user.getPassword(); |
|
116 |
if(name == null || password == null) { |
|
117 |
return UserModelStatusCodes.USER_LOGIN_FAILED; |
|
118 |
} |
|
119 |
|
|
114 | 120 |
User u = userRepository.findByName(user.getName()); |
115 | 121 |
//TODO request to OAuth for authentication |
116 |
return u == null ? UserModelStatusCodes.USER_LOGIN_FAILED : UserModelStatusCodes.USER_LOGGED_IN; |
|
122 |
final boolean passwordMatches = comparePassword(password,u.getPassword()); |
|
123 |
|
|
124 |
return passwordMatches ? UserModelStatusCodes.USER_LOGIN_FAILED : UserModelStatusCodes.USER_LOGGED_IN; |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* Method compares user password with stored hash |
|
129 |
* @param password String user provided password |
|
130 |
* @param hash String hash saved in database |
|
131 |
* @return true if hashes are the same |
|
132 |
*/ |
|
133 |
boolean comparePassword(String password, String hash){ |
|
134 |
final String passwordHash = this.hashPassword(password); |
|
135 |
return hash.equals(passwordHash); |
|
117 | 136 |
} |
118 | 137 |
|
119 | 138 |
/** |
Také k dispozici: Unified diff
#10244 přihlášení uživatele porovnání otisků hesla