# BCryptPasswordEncoder 第一次配置成功 boot1.5版本 **Repository Path**: cs1145461707/BCryptPasswordEncoder_1.5 ## Basic Information - **Project Name**: BCryptPasswordEncoder 第一次配置成功 boot1.5版本 - **Description**: No description available - **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.2.RELEASE 这个版本 现在是1.5.x版本 此时默认不是BCryptPasswordEncoder 需要这句auth.userDetailsService(customUserService()).passwordEncoder(passwordEncoder()); 然后数据库删除{id}这个东西 使用cache3数据库 修复user.getName 空指针异常 添加匹配规则,允许有些网页不需要授权 参考这篇 http://www.tianshouzhi.com/api/tutorials/spring_security_4/266 // 测试权限,本文授予的角色是 ROLE_ADMIN