Search code examples
grailsgrails-2.0shiro

Delete user registered with shiro security plugin in grails


i have a form for checking the login and password before delete the user. this one:

<table>
        <g:form action="deleteUser">
            <tr>
                <td><label for="username">Login: </label></td>
                <td><g:textField name="username"/>
            </tr>
            <tr>
                <td><label for="password">Password: </label></td>
                <td><g:passwordField name="password"/></td>
            </tr>
            <tr>
                <td colspan="2"><g:submitButton name="delete" value="Delete"/></td>
            </tr>
        </g:form>
    </table>

how i can do logic for this if password in sha512hash(user registered via shiro plugin). how i can check the password as string from the password form with hash code from db? may i use the authenticate method from DbRealm class, if yes then HOW?

P.S. sorry for my english!


Solution

  • If I do understand your question the right way, you just want to verify the users password a last time before you delete the user.

    In the database, only the hash of the password is stored. But you can just compare the hash of the new password with the hash of the stored password:

    def dbhash = ShiroUser.findByUsername(params.username)?.passwordHash
    if (new Sha256Hash("password").toHex()==dbhash) {
      //delete user
    } else {
      //display error message
    }
    

    Hope that helps!