File tree Expand file tree Collapse file tree 2 files changed +5
-2
lines changed
src/main/java/mate/academy Expand file tree Collapse file tree 2 files changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ public User get(Long id) {
44
44
public Optional <User > findByEmail (String email ) {
45
45
try (Session session = HibernateUtil .getSessionFactory ().openSession ()) {
46
46
Query <User > query = session .createQuery ("from User where email"
47
- + "=:email" );
47
+ + "=:email" , User . class );
48
48
query .setParameter ("email" , email );
49
49
return query .uniqueResultOptional ();
50
50
} catch (Exception exception ) {
Original file line number Diff line number Diff line change @@ -16,9 +16,12 @@ public class AuthenticationServiceImpl implements AuthenticationService {
16
16
@ Override
17
17
public User login (String email , String password ) throws AuthenticationException {
18
18
Optional <User > byEmail = userService .findByEmail (email );
19
+ if (byEmail .isEmpty ()) {
20
+ throw new AuthenticationException ("Invalid email" );
21
+ }
19
22
User user = byEmail .get ();
20
23
String hashedPassword = HashUtil .hashPassword (password , user .getSalt ());
21
- if (!hashedPassword .equals (user .getPassword ()) || byEmail . isEmpty () ) {
24
+ if (!hashedPassword .equals (user .getPassword ())) {
22
25
throw new AuthenticationException ("Invalid password or email" );
23
26
}
24
27
return user ;
You can’t perform that action at this time.
0 commit comments