zoukankan      html  css  js  c++  java
  • 加密算法

    BCrypt加密算法

      用户表的密码通常使用MD5等不可逆算法加密后存储,为防止彩虹表破解更会先使用一个特定的字符串(如域名)加密,然后再使用一个随机的salt(盐值)加密.特定字符串是程序代码中固定的,salt是每个密码单独随机,一般给用户表加一个字段单独存储,比较麻烦,BCrypt算法将salt随机并混入最终加密后的密码,验证时也无需单独提供之前的salt,从而无需单独处理salt问题.

    使用加密算法时:

    @RequestMapping("/add")
        public Result add(@RequestBody TbSeller seller){
            //密码加密
            BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
            String password = passwordEncoder.encode(seller.getPassword());
            seller.setPassword(password);
            try {
                sellerService.add(seller);
                return new Result(true, "增加成功");
            } catch (Exception e) {
                e.printStackTrace();
                return new Result(false, "增加失败");
            }
        }

    然后需要进行的配置为:

    <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>  

    在页面中进行配置

    <div class="pull-right">
          <a href="../logout" class="btn btn-default btn-flat">注销</a>
    </div>

    退出登录:

    <!-- 页面拦截规则 -->
    <http use-expressions="false">
        <intercept-url pattern="/**" access="ROLE_SELLER" />
        <logout logout-url="/logout" logout-success-url="/shoplogin.html"/>

      

  • 相关阅读:
    第一章(认识jQuery)
    csv、txt读写及模式介绍
    命令行参数
    WebDriverWait等设置等待时间和超时时间
    js加载页面使用execute_script选定加载位置
    pip镜像源配置
    python字符编码
    scrapy设置代理
    urllib2设置代理
    禁止chrome自动更新
  • 原文地址:https://www.cnblogs.com/qingmuchuanqi48/p/10976422.html
Copyright © 2011-2022 走看看