Coder Social home page Coder Social logo

Comments (2)

zorohu avatar zorohu commented on July 29, 2024

加密方式这里是否考虑通过SPI机制去实现是否会更好,内置默认加密方式,用户也可使用自己的加密方式

from ballcat.

Hccake avatar Hccake commented on July 29, 2024

加密方式这里是否考虑通过SPI机制去实现是否会更好,内置默认加密方式,用户也可使用自己的加密方式

设计之初就提供了这样的机制,用户可以通过自定义 PasswordEncoder 实现密码加解密方式替换,目前主要是修改密码这里写死了,需要修改。

当前实现

目前登录时,会利用注册在 spring 容器中的密码编码器 PasswordEncoder 实例,进行密码的加密以及匹配:

ballcat 默认的 PasswordEncoder 使用的是 DelegatingPasswordEncoder(用户可以自己注册 PasswordEncoder 进行替换这一行为),使用该密码编码器加密时获得的密文格式为:{bcrypt}算法密文,进行密码匹配测试时使用的数据格式为:{加密算法}算法密文

目前支持以下加密算法,当加密算法部分为空时,默认使用 bcrypt 算法。

  • bcrypt
  • ldap
  • MD4
  • MD5
  • noop
  • pbkdf2
  • scrypt
  • SHA-1
  • SHA-256
  • sha256
  • sha256

示例

如明文密码:a123456
使用 MD5 加密后的的密文为 dc483e80a7a0bd9ef71d8cf973673924
使用 bcrypt 加密后的密文为 $2a$10$iBJZLHRVrjpJCKVNUZw6B.wbdClhvVdT91KbN25sTjbn1MJT4wqmm

那么,当使用 DelegatingPasswordEncoder 进行匹配时,以下几种数据都将返回 true:

  • $2a$10$iBJZLHRVrjpJCKVNUZw6B.wbdClhvVdT91KbN25sTjbn1MJT4wqmm
  • {bcrypt}$2a$10$iBJZLHRVrjpJCKVNUZw6B.wbdClhvVdT91KbN25sTjbn1MJT4wqmm
  • {MD5}dc483e80a7a0bd9ef71d8cf973673924
  • {noop}a123456

也就是说在 sys_user 表中的 password 字段,支持同时存在多种加密方式,方便密码加密算法的迁移

from ballcat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.