1 17 18 package org.apache.james.userrepository; 19 20 import org.apache.james.security.DigestUtil; 21 import org.apache.james.services.User; 22 23 import java.io.Serializable ; 24 import java.security.NoSuchAlgorithmException ; 25 26 33 34 public class DefaultUser implements User, Serializable { 35 36 private String userName; 37 private String hashedPassword; 38 private String algorithm ; 39 40 46 public DefaultUser(String name, String hashAlg) { 47 userName = name; 48 algorithm = hashAlg; 49 } 50 51 60 public DefaultUser(String name, String passwordHash, String hashAlg) { 61 userName = name; 62 hashedPassword = passwordHash; 63 algorithm = hashAlg; 64 } 65 66 71 public String getUserName() { 72 return userName; 73 } 74 75 82 public boolean verifyPassword(String pass) { 83 try { 84 String hashGuess = DigestUtil.digestString(pass, algorithm); 85 return hashedPassword.equals(hashGuess); 86 } catch (NoSuchAlgorithmException nsae) { 87 throw new RuntimeException ("Security error: " + nsae); 88 } 89 } 90 91 98 public boolean setPassword(String newPass) { 99 try { 100 hashedPassword = DigestUtil.digestString(newPass, algorithm); 101 return true; 102 } catch (NoSuchAlgorithmException nsae) { 103 throw new RuntimeException ("Security error: " + nsae); 104 } 105 } 106 107 112 protected String getHashedPassword() { 113 return hashedPassword; 114 } 115 116 121 protected String getHashAlgorithm() { 122 return algorithm; 123 } 124 125 126 } 127 | Popular Tags |