source: Git/src/main/java/com/wediscussmovies/project/model/PasswordEncoder.java@ 2a5d6a3

main
Last change on this file since 2a5d6a3 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
Line 
1package com.wediscussmovies.project.model;
2
3
4import java.math.BigInteger;
5import java.nio.charset.StandardCharsets;
6import java.security.MessageDigest;
7import java.security.NoSuchAlgorithmException;
8
9public 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.