【问题标题】:how to generate md5 + salt password for salted-hash spring 4如何为 salted-hash spring 4 生成 md5 + salt 密码
【发布时间】:2017-03-15 04:38:56
【问题描述】:

我正在将遗留系统迁移到 Java Web 应用程序。现在我正在使用没有 xml 的 spring mvc + spring security + spring boot jpa。但是当我使用 bcyrpt 以 spring security 4 登录时遇到问题。使用 md5 + salted 生成的遗留数据库密码。

【问题讨论】:

    标签: spring spring-security md5 salt


    【解决方案1】:

    你需要类似这样的配置:

    @Configuration
    @EnableWebMvcSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        @Autowired
        Md5PasswordEncoder md5CryptEncoder;
    
        @Autowired
        UserDetailsService myDetailsService
    
        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    
                DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
                authProvider.setPasswordEncoder(md5CryptEncoder);
                authProvider.setUserDetailsService(myDetailsService);
                ReflectionSaltSource saltSource = new ReflectionSaltSource();
                saltSource.setUserPropertyToUse("salt");
                authProvider.setSaltSource(saltSource);
                auth.authenticationProvider(authProvider);
        }
    }
    

    但您必须使用正确的编码器配置 Auth。

    【讨论】:

    • 这是我的编码器,但是加盐怎么样? @Bean public Md5PasswordEncoder passwordEncoder(){ Md5PasswordEncoder md5PasswordEncoder = new Md5PasswordEncoder();返回 md5PasswordEncoder; }
    • 查看这篇文章Spring MD5 Salt
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-09
    • 2017-09-15
    • 1970-01-01
    • 2014-08-01
    • 2011-08-09
    • 2014-03-09
    • 1970-01-01
    相关资源
    最近更新 更多