main
Last change
on this file since 7f36551 was 2a5d6a3, checked in by Petar Partaloski <ppartaloski@…>, 2 years ago |
Controller, Repository and Service layer improvements, Entity updating
|
-
Property mode
set to
100644
|
File size:
939 bytes
|
Rev | Line | |
---|
[2a5d6a3] | 1 | package com.wediscussmovies.project.model;
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | import java.math.BigInteger;
|
---|
| 5 | import java.nio.charset.StandardCharsets;
|
---|
| 6 | import java.security.MessageDigest;
|
---|
| 7 | import java.security.NoSuchAlgorithmException;
|
---|
| 8 |
|
---|
| 9 | public class PasswordEncoder {
|
---|
| 10 | public static byte[] getSHA(String input) throws NoSuchAlgorithmException
|
---|
| 11 | {
|
---|
| 12 | MessageDigest md = MessageDigest.getInstance("SHA-512");
|
---|
| 13 |
|
---|
| 14 | return md.digest(input.getBytes(StandardCharsets.UTF_8));
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | public static String toHexString(byte[] hash)
|
---|
| 18 | {
|
---|
| 19 | BigInteger number = new BigInteger(1, hash);
|
---|
| 20 |
|
---|
| 21 | StringBuilder hexString = new StringBuilder(number.toString(16));
|
---|
| 22 |
|
---|
| 23 | while (hexString.length() < 32)
|
---|
| 24 | {
|
---|
| 25 | hexString.insert(0, '0');
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | return hexString.toString();
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public static String getEncodedPasswordString(String password) throws NoSuchAlgorithmException {
|
---|
| 32 | return toHexString(getSHA(password));
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | }
|
---|
| 36 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.