1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
public void userRegistration(userSubscription user)
{
MessageDigest md;
String algorithm="SHA-256";
byte[] hash;
String password="";
Date date = new Date(System.currentTimeMillis());
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
Timestamp time = new Timestamp(sqlDate.getTime());
//Password encryption
try
{
md=MessageDigest.getInstance(algorithm);
hash=md.digest(user.getPassword().getBytes("UTF-8"));
StringBuilder sb = new StringBuilder(hash.length*2);
for (byte b : hash) {
sb.append( String.format("%2x", b) );
}
password = sb.toString();
}
catch (NoSuchAlgorithmException e)
{
System.out.println("L'algo n'existe pas !!");
e.printStackTrace();
}
catch (UnsupportedEncodingException e)
{
System.out.println("L'encodage n'est pas bon");
e.printStackTrace();
}
userDao.insertUserAccess(user,time,password);
userDao.insertUserInformations(user);
} |