Coverage Report - booking.model.util.SecurityUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
SecurityUtil
72%
13/18
100%
2/2
2,5
 
 1  
 package booking.model.util;
 2  
 
 3  
 import java.io.UnsupportedEncodingException;
 4  
 import java.security.MessageDigest;
 5  
 import java.security.NoSuchAlgorithmException;
 6  
 import java.util.Formatter;
 7  
 
 8  0
 public class SecurityUtil {
 9  
 
 10  
         public static String encryptPassword(String password)
 11  
         {
 12  5
             String sha1 = "";
 13  
             try
 14  
             {
 15  5
                 MessageDigest crypt = MessageDigest.getInstance("SHA-1");
 16  5
                 crypt.reset();
 17  5
                 crypt.update(password.getBytes("UTF-8"));
 18  5
                 sha1 = byteToHex(crypt.digest());
 19  
             }
 20  0
             catch(NoSuchAlgorithmException e)
 21  
             {
 22  0
                 e.printStackTrace();
 23  
             }
 24  0
             catch(UnsupportedEncodingException e)
 25  
             {
 26  0
                 e.printStackTrace();
 27  5
             }
 28  5
             return sha1;
 29  
         }
 30  
 
 31  
         private static String byteToHex(final byte[] hash)
 32  
         {
 33  5
             Formatter formatter = new Formatter();
 34  105
             for (byte b : hash)
 35  
             {
 36  100
                 formatter.format("%02x", b);
 37  
             }
 38  5
             String result = formatter.toString();
 39  5
             formatter.close();
 40  5
             return result;
 41  
         }
 42  
         
 43  
 }