-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
998 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
config-web/src/main/java/com/github/autoconf/shiro/PasswordHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.github.autoconf.shiro; | ||
|
||
import com.github.autoconf.entity.User; | ||
import org.apache.shiro.crypto.RandomNumberGenerator; | ||
import org.apache.shiro.crypto.SecureRandomNumberGenerator; | ||
import org.apache.shiro.crypto.hash.SimpleHash; | ||
import org.apache.shiro.util.ByteSource; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
public class PasswordHelper { | ||
private RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator(); | ||
|
||
@Value("${shiro.password.algorithmName}") | ||
private String algorithmName = "md5"; | ||
@Value("${shiro.password.hashIterations}") | ||
private int hashIterations = 2; | ||
|
||
public void setRandomNumberGenerator(RandomNumberGenerator randomNumberGenerator) { | ||
this.randomNumberGenerator = randomNumberGenerator; | ||
} | ||
|
||
public void setAlgorithmName(String algorithmName) { | ||
this.algorithmName = algorithmName; | ||
} | ||
|
||
public void setHashIterations(int hashIterations) { | ||
this.hashIterations = hashIterations; | ||
} | ||
|
||
public void encryptPassword(User user) { | ||
|
||
user.setSalt(randomNumberGenerator.nextBytes().toHex()); | ||
|
||
String newPassword = | ||
new SimpleHash(algorithmName, user.getPassword(), ByteSource.Util.bytes(user.getCredentialsSalt()), hashIterations).toHex(); | ||
|
||
user.setPassword(newPassword); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.