Skip to content

Commit 98b058f

Browse files
committed
I almost have completed
1 parent 9b520b9 commit 98b058f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/main/java/mate/academy/dao/impl/UserDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public User get(Long id) {
4444
public Optional<User> findByEmail(String email) {
4545
try (Session session = HibernateUtil.getSessionFactory().openSession()) {
4646
Query<User> query = session.createQuery("from User where email"
47-
+ "=:email");
47+
+ "=:email", User.class);
4848
query.setParameter("email", email);
4949
return query.uniqueResultOptional();
5050
} catch (Exception exception) {

src/main/java/mate/academy/security/impl/AuthenticationServiceImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ public class AuthenticationServiceImpl implements AuthenticationService {
1616
@Override
1717
public User login(String email, String password) throws AuthenticationException {
1818
Optional<User> byEmail = userService.findByEmail(email);
19+
if (byEmail.isEmpty()) {
20+
throw new AuthenticationException("Invalid email");
21+
}
1922
User user = byEmail.get();
2023
String hashedPassword = HashUtil.hashPassword(password, user.getSalt());
21-
if (!hashedPassword.equals(user.getPassword()) || byEmail.isEmpty()) {
24+
if (!hashedPassword.equals(user.getPassword())) {
2225
throw new AuthenticationException("Invalid password or email");
2326
}
2427
return user;

0 commit comments

Comments
 (0)