【问题标题】:Acegi password encryptionAcegi 密码加密
【发布时间】:2010-12-01 03:23:26
【问题描述】:

我正在使用 acegi groovy 插件进行用户注册和身份验证。 插件自带的User域类有如下定义(和cmets)。

class User {
static transients = ['pass']
static hasMany = [authorities: Role]
static belongsTo = Role

/** Username */
String username
/** User Real Name*/
String userRealName
/** MD5 Password */
String passwd
/** enabled */
boolean enabled

String email
boolean emailShow

/** description */
String description = ''
...

}

等等。所以我假设密码加密方式是MD5。

我必须注册数千个用户,为每个用户生成一个随机密码。 (用户名已经给出)。

我编写了一个脚本,它生成随机纯密码和 MD5 加密密码和 将相应的插入到数据库中。 很遗憾,这些用户都无法登录。

acegi 安全插件是否使用 MD5 加密?

似乎它正在使用其他东西。 不幸的是,我在文档中没有找到任何东西。

有人知道这个加密是怎么做的吗?

谢谢!

路易斯

【问题讨论】:

    标签: passwords md5 spring-security


    【解决方案1】:

    如果您使用DaoAuthenticationProvider 并且未设置passwordEncoder 属性,则默认密码编码器为PlaintextPasswordEncoder。要配置 MD5 密码编码器,请执行

      <bean
          id="passwordEncoder"
          class="org.acegisecurity.providers.encoding.Md5PasswordEncoder"/>
    
      <bean
          id="daoAuthenticationProvider"
          class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
        <property name="userDetailsService" ref="userDetailsService"/>
        <property name="passwordEncoder" ref="passwordEncoder"/>
      </bean>
    

    【讨论】:

    • 感谢您的回答。为你+1。不,我没有设置任何东西。现在,我在 DefaultSecurityConfig.groovy 中发现该算法是“SHA”。你知道如何生成 SHA 加密的密码吗?谢谢!
    • echo -n 密码 | openssl sha1
    【解决方案2】:

    或者您可以使用 authenticateService.encodePassword("password")。以插件的RegisterController的save方法为例

    【讨论】:

      猜你喜欢
      • 2010-12-11
      • 2011-04-21
      • 2012-12-03
      • 2010-09-05
      • 2010-11-06
      相关资源
      最近更新 更多