package com.dji.sample.manage.service.password;

import com.dji.sample.manage.model.password.PasswordRule;
import com.dji.sample.manage.model.password.PasswordRuleContext;
import com.dji.sample.manage.model.password.PasswordRuleResult;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Rule 5 – Weak-password blacklist.
 * Password must NOT appear in the list of publicly known / commonly guessed passwords.
 */
public class WeakPasswordRule implements PasswordRule {

    private static final Set<String> WEAK_PASSWORDS = new HashSet<>(Arrays.asList(
            "password", "password1", "password123", "passw0rd",
            "admin", "admin123", "administrator",
            "12345678", "123456789", "1234567890",
            "qwerty", "qwerty123", "qwertyuiop",
            "abc123", "abcd1234",
            "iloveyou", "welcome", "login", "master",
            "111111", "222222", "666666", "888888", "123123"
    ));

    @Override
    public PasswordRuleResult validate(String password, PasswordRuleContext context) {
        if (WEAK_PASSWORDS.contains(password.toLowerCase())) {
            return PasswordRuleResult.fail(
                    "Password is too common or weak. Please choose a more complex password");
        }
        return PasswordRuleResult.ok();
    }

    @Override
    public String getRuleName() {
        return "WeakPasswordBlacklist";
    }

}
