package com.ruoyi.common.utils;

import java.security.SecureRandom;

/**
 * @author du
 * @since 2024/11/26 10:04
 */
public class PasswordGenerator {
    public static   String  password() {
        //定义字符池
        String upperCase = "ABCDEFGHIJKLMNOPORSTUVWXYZ";
        String lowercase = "abcdefghijklmnopqrstuvwxyz";
        String numbers = "0123456789";
        String specialcharacters = "!@#$%^&*";
        String allcharacters = upperCase + lowercase + numbers + specialcharacters;
        //创建随机数生成器
        SecureRandom random = new SecureRandom();// 使用 SecureRandom 以增加安全性
        StringBuilder password = new StringBuilder(16);// 使用 stringBuilder 来构建字符串
        for (int i = 0; i < 16; i++) {
            int index = random.nextInt(allcharacters.length());// 随机选择字符下标
            password.append(allcharacters.charAt(index));//将字符添加到密码中
        }
        return password.toString();
    }
}
