package space.anyi.petServiceManagementSystem.server.config; import org.springframework.stereotype.Component; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @Component public class PasswordConfig { private static final String SALT = "PetService2026!@#"; public String encrypt(String password) { try { String toEncrypt = password + SALT; MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digest = md.digest(toEncrypt.getBytes()); StringBuilder sb = new StringBuilder(); for (byte b : digest) { sb.append(String.format("%02x", b & 0xff)); } return sb.toString(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("MD5 encryption error", e); } } public boolean matches(String rawPassword, String encryptedPassword) { return encrypt(rawPassword).equals(encryptedPassword); } }