赞
踩
不可逆 (哈希算法) MD5 32位字符串
可逆 密钥 Bcrypt需要60位
BCrypt加密算法
用户表的密码通常使用MD5等不可逆算法加密后存储,为防止彩虹表破解更会先使用一个特定的字符串(如域名)加密,然后再使用一个随机的salt(盐值)加密。 特定字符串是程序代码中固定的,salt是每个密码单独随机,一般给用户表加一个字段单独存储,比较麻烦。 BCrypt算法将salt随机并混入最终加密后的密码,验证时也无需单独提供之前的salt,从而无需单独处理salt问题。
- BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
- String password = passwordEncoder.encode(seller.getPassword());
- seller.setPassword(password);
spring-security.xml ,添加如下配置,相当于密码加密的工具类
↓↓↓↓↓↓↓
<beans:bean id="bcryptEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />
再添加都认证管理器中
- <authentication-manager alias="authenticationManager">
- <authentication-provider user-service-ref='userDetailService'>
- <password-encoder ref="bcryptEncoder"></password-encoder>
- </authentication-provider>
- </authentication-manager>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。