package de.htwsaar.webshop.service.impl;

import de.htwsaar.webshop.service.PasswordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.stereotype.Service;


/**
 * Implementation of {@link PasswordService} responsible for hashing and verifying passwords.
 */
@Service
@Slf4j
public class PasswordServiceImpl implements PasswordService {
    /**
     * A way to generate Password after BCrypt Standard <br>
     * This is computationally expensive
     *
     * @return a non-deterministic Salt for BCrypt.
     */
    @Override
    public String hashPassword(String password) {
        return BCrypt.hashpw(password, BCrypt.gensalt(12));
    }

    @Override
    public boolean verifyPassword(String password, String hashedPassword) {
        return BCrypt.checkpw(password, hashedPassword);
    }
}