sam2099 commented on issue #1022:
URL: https://github.com/apache/shiro/issues/1022#issuecomment-1878036236

   @lprimak 
   Thank you !It's done .  
   code as below
   
   ```java
    @Test
       void shiro1PasswordsMatchByShiro2() {
           DefaultPasswordService passwordService = new PasswordService();
           passwordService.setHashFormat(new Shiro1CryptFormat());
   
           //authenticate   example
           Assertions.assertTrue(passwordService.passwordsMatch("123456", 
toHash("$shiro1$SHA-256$1$$jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI=")));
           Assertions.assertTrue(passwordService.passwordsMatch("123456789o", 
toHash("$shiro1$SHA-256$1$$qdTQef3V/i7GigwRj0DWlgt2oAMGGbZgjOt4V4lNNoA=")));
           
Assertions.assertTrue(passwordService.passwordsMatch("SDGSDG123456789o#@", 
toHash("$shiro1$SHA-256$1$$6kVafxRNvmDiFQDLEaN09D+UkkLEYfRPSBzNfCKf6Fc=")));
           
Assertions.assertTrue(passwordService.passwordsMatch("我是密码123asdfA#@", 
toHash("$shiro1$SHA-256$1$$+sE4/mtXoDeGiywr0Yt93o1QhhLHgcrshkvV6NjnjaQ=")));
       }
       Hash toHash(String encryptedPassword) {
           if (new DefaultHashFormatFactory().getInstance(encryptedPassword) 
instanceof ParsableHashFormat phf) {
               if (phf.parse(encryptedPassword) instanceof SimpleHash sh) {
                   sh.setSalt(ByteSource.Util.bytes(new byte[0]));
                   sh.setIterations(1);
                   return sh;
               }
           }
           throw new IllegalArgumentException("Invalid encrypted password");
       }
       private final static class PasswordService extends 
DefaultPasswordService {
           @Override
           protected HashRequest createHashRequest(ByteSource plaintext) {
               return new HashRequest.Builder().setSource(plaintext)
                       .setAlgorithmName(Sha256Hash.ALGORITHM_NAME)
                       .build();
           }
       }
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to