Spring security login interface authentication principle

Gateway+spring security is used. The project originally planned to use gateway unified authentication. The integration steps click here
. At that time, I did not go deep into security. Today, I accidentally saw the code and found that the verification password was encrypted, but the password submitted in the login form was not encrypted. look at the code

Log in to the interface to verify whether the account password is correct

  1. postman login interface call
    insert image description here

  2. The findByUsername method is to verify the password of the login interface, we need to implement this method to read the database account password. The database stores plaintext passwords, and the return value is encrypted when the code encapsulates it, so how to verify that the passwords are consistent internally?
    insert image description here

  3. Use the idea breakpoint to see who called the findByUsername method:
    insert image description here
    insert image description here
    in this way, you can find out who called it, and then continue to execute, and found that this method is for comparing passwords
    insert image description here
    insert image description here

  4. It is found that the prefix of the encrypted database password represents the encryption type
    insert image description here
    supported by the encryption type:insert image description here

  5. At this point, the encryption method has been obtained, continue to the next step
    insert image description here

  6. It is found that the account number entered into the login interface is encrypted, and then it is judged whether the encrypted password is consistent with the password of the database table. The insert image description here
    encryption logic is very complicated, that is, to encrypt the password
    insert image description here
    insert image description here

  7. This is the wrong password, the generated ciphertext is inconsistent
    insert image description here

  8. Use the correct password to call the login interface, and the generated ciphertext is consistentinsert image description here
    insert image description here
    insert image description here

Guess you like

Origin blog.csdn.net/weixin_48835367/article/details/131475825