backend rewritten in rust #11

Merged
mixel merged 9 commits from new-backend into main 2024-10-04 17:28:26 +02:00
2 changed files with 26 additions and 4 deletions
Showing only changes of commit 50aacf9cb6 - Show all commits

View file

@ -0,0 +1,22 @@
package com.mixel.docusphere.service;
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
import org.springframework.stereotype.Service;
@Service
public class PasswordService {
private final Argon2PasswordEncoder passwordEncoder;
public PasswordService() {
this.passwordEncoder = new Argon2PasswordEncoder(16, 32, 1, 4096, 3);
}
public String hashPassword(String password) {
return passwordEncoder.encode(password);
}
public boolean checkPassword(String rawPassword, String encodedPassword) {
return passwordEncoder.matches(rawPassword, encodedPassword);
}
}

View file

@ -18,12 +18,12 @@ public class UserService {
private final UserRepository userRepository;
private final Argon2PasswordEncoder passwordEncoder;
private final PasswordService passwordService;
// Constructor
public UserService(UserRepository userRepository) {
this.passwordEncoder = new Argon2PasswordEncoder(16, 32, 1, 4096, 3);
public UserService(UserRepository userRepository, PasswordService passwordService) {
this.userRepository = userRepository;
this.passwordService = passwordService;
}
public List<UserRespondDTO> findAll() {
@ -59,7 +59,7 @@ public class UserService {
private void isPasswordAlreadySet(UserRequestDTO userRequestDTO, User user) {
if (userRequestDTO.getPassword() != null && !userRequestDTO.getPassword().isEmpty()) {
user.setPasswordHash(passwordEncoder.encode(userRequestDTO.getPassword()));
user.setPasswordHash(passwordService.hashPassword(userRequestDTO.getPassword()));
}
}