Skip to content
Snippets Groups Projects

User registration

Merged Mads Lundegaard requested to merge user_registration into dev
2 unresolved threads
Files
6
@@ -93,4 +93,32 @@ public class LoginRepository extends GenericRepository<Login, String>{
}
return false;
}
/**
* Method for setting the password on the user for the first time
*
* @param username of the user that will have the password set
* @param password password that will be set
* @return
*/
public boolean setPassword(String username, String password) {
ArrayList<String> info = new ArrayList<>();
try {
Optional<Login> login = findById(username);
if(login.isPresent()) {
info = Authentication.setPassword(password);
String saltString = info.get(0);
String hastString = info.get(1);
login.get().setPasswordSalt(saltString);
login.get().setHash(hastString);
save(login.get());
return true;
}
}
catch (IllegalArgumentException e) {
e.printStackTrace();
}
return false;
}
    • Why do you try to get the login, if you are setting the password for the first time? If I understand this correctly you are creating a Login, ie registering a user with password. Therefore you will not find a login and nothing will happen.

      All of these methods really belong in the LoginService or UserService respectively because a repository only concerns itself with interacting with the database and not with business logic.

Please register or sign in to reply
}
\ No newline at end of file
Loading