一、

1.Focusing on the authentication query, you can see that user passwords are expected to be stored in the database. The only problem with that is that if the passwords are stored in plain text, they’re subject to the prying eyes of a hacker. But if you encode the password in the database, then authentication will fail because it won’t match the plain text password submitted by the user.

 @Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth
.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery(
"select username, password, true " +
"from Spitter where username=?")
.authoritiesByUsernameQuery(
"select username, 'ROLE_USER' from Spitter where username=?")
.passwordEncoder(new StandardPasswordEncoder("53cr3t"));
}

passwordEncoder方法接收PasswordEncoder接口的实现为参数,Spring提供了有3种实现:BCryptPasswordEncoder , NoOpPasswordEncoder , andStandardPasswordEncoder

接口代码如下:

public interface PasswordEncoder {
String encode(CharSequence rawPassword);
boolean matches(CharSequence rawPassword, String encodedPassword);
}

it’s important to understand that the password in the database is never decoded. Instead, the password that the user enters at login is encoded using the same algorithm and is then compared with the encoded password in the database. That comparison is performed in the PasswordEncoder ’s matches() method.

最新文章

  1. [转载] Jenkins入门总结
  2. 学习使用MAC
  3. easyui_动态添加隐藏toolbar按钮
  4. Castle学习笔记----初探IOC容器
  5. javascript小实例,PC网页里的拖拽(转)
  6. gridview动态添加列的问题
  7. UIStackView相关
  8. 王立平-- ContentValues , HashTable , HashMap差别
  9. boolean类型相关
  10. mkdir 命令详解
  11. Java8 中 ConcurrentHashMap工作原理的要点分析
  12. LAN、WAN、WLAN、WiFi之间的区别
  13. matlab提取wind底层数据库操作
  14. javascript OOP(上)(八)
  15. NSL:CPK_NN神经网络实现预测哪个样本与哪个样本处在同一层,从而科学规避我国煤矿突水灾难—Jason niu
  16. 3分钟上手log4net
  17. 取消Eclipse控制台显示行数的限制
  18. zabbix 添加用户 配置权限
  19. 玩转ptrace(转)
  20. Entity Framework 同一个上下文中,如何进行对同一个实体进行指定字段更新

热门文章

  1. PDA库位商品出库适配算法
  2. JAVA解析xml的五种方式比较
  3. Spring boot 1.3.5 RELEASE 官方文档中文翻译--Part2:新手入门
  4. java.util.HashSet源码分析
  5. JAVA_SE复习(OOP2)
  6. Ueditor设置默认字体
  7. 1_jz2440在linux下烧写裸机程序
  8. Kail安装Parallels tools
  9. shadow服务端、客户端配置流程
  10. canvas主要属性和方法