# security-BCryptPasswordEncoder **Repository Path**: cs1145461707/security-BCryptPasswordEncoder ## Basic Information - **Project Name**: security-BCryptPasswordEncoder - **Description**: BCryptPasswordEncoder 第一次配置成功 boot2.0版本 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-06-12 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 终于设置成功了 BCryptPasswordEncoder 这个加密选项 首先参考这篇文章: https://www.devglan.com/spring-security/spring-boot-security-password-encoding-bcrypt-encoder 用处很大 但是已经老了 不适合新的 看这个文档得到启发 默认就是 BCryptPasswordEncoder 然后存的格式是这样 {id}encodedPassword 所以先写了生成类 GeneratePass 然后 删除 @Bean public PasswordEncoder passwordEncoder(){ PasswordEncoder encoder = new BCryptPasswordEncoder(); return encoder; } 还有这个 .passwordEncoder(passwordEncoder()); 就成功了 3. 设置有些用户可以通过,有些用户通不过 throw new UsernameNotFoundException("权限不允许"); 关注这个,不能return null 参考https://stackoverflow.com/questions/34538768/why-does-userdetailsservice-return-null-in-spring-boot-app 下面的回答 千万注意这是2.0版本 与1.5不一样 从下面这段描述体会这两个版本差别 // 1.5.x的,描述 现在是1.5.x版本 此时默认不是BCryptPasswordEncoder 需要这句auth.userDetailsService(customUserService()).passwordEncoder(passwordEncoder()); 然后数据库删除{id}这个东西 使用cache3数据库