006nacos修改默认密码

一、使用代码工具生成修改nacos默认密码

/**
 * @author arunyang
 * Ref: https://nacos.io/zh-cn/docs/console-guide.html
 * Reference: https://stackoverflow.com/questions/25844419/why-bcryptpasswordencoder-from-spring-generate-different-outputs-for-same-input
 */

public class PasswordEncoderUtil {
    // spring 4.0.0
    public static void main(String[] args) {
        org.springframework.security.crypto.password.PasswordEncoder encoder
                = new org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder();
        //(1) "123456" - plain text - user input from user interface
        String passwd = encoder.encode("Eixxxxw");
        //(2) passwd - password from database
        System.out.println(passwd); // print hash

        //(3)验证:
        System.out.println(encoder.matches("Eixxxxw", passwd));
        //(4)修改nacos密码:
        //INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2asdf8vRl4EixxxxwEixxxxwmCTZjDEixxxxwEixxxxwEixxxxwEixxxxwKTmoxgVzDrW', TRUE);
        //INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');
    }
}

 

posted @ 2023-03-13 18:01  arun_yh  阅读(528)  评论(0编辑  收藏  举报