• 加密算法


    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 Masonry 插件创建瀑布流式的页面
    ecshop标签大全 各个页面常用标签大全
    Logistic Regression Using Gradient Descent -- Binary Classification 代码实现
    Linear Regression Using Least Squares Method 代码实现
    eigen quick reference
    Linear Regression Using Gradient Descent 代码实现
    eigen 笔记2
    eigen 笔记1
    Floyd 判圈算法
    SQL Expression Language Tutorial 学习笔记二
  • 原文地址:https://www.cnblogs.com/qingmuchuanqi48/p/10976422.html
Copyright © 2020-2023  润新知