Grails Spring Security Core - Generating password manually

468 views Asked by At

I am trying generate a password manually to insert it directly into the database. But unfortunatelly I doesn´t work.

Spring security core is set to use MD5 encoding. I generate a new password in a md5 hash generation webpage, update the bbdd but I can not log in with that user.

I guess it has some specific structure before enconding but I don´t know it.

1

There are 1 answers

0
Nils On

Just have a look in the source code of the basespasswordencoder class.

protected String mergePasswordAndSalt(String password, Object salt, boolean strict) {
        if (password == null) {
            password = "";
        }

        if (strict && (salt != null)) {
            if ((salt.toString().lastIndexOf("{") != -1) || (salt.toString().lastIndexOf("}") != -1)) {
                throw new IllegalArgumentException("Cannot use { or } in salt.toString()");
            }
        }

        if ((salt == null) || "".equals(salt)) {
            **return password**;
        } else {
            **return password + "{" + salt.toString() + "}"**;
        }
    }
}

http://grepcode.com/file/repo1.maven.org/maven2/org.springframework.security/spring-security-core/3.0.1.RELEASE/org/springframework/security/authentication/encoding/BasePasswordEncoder.java#BasePasswordEncoder.mergePasswordAndSalt%28java.lang.String%2Cjava.lang.Object%2Cboolean%29