1 package org.snipsnap.user; 2 3 import org.snipsnap.snip.storage.UserStorage; 4 5 import java.util.Random ; 6 import java.util.Map ; 7 import java.util.HashMap ; 8 9 33 34 public class PasswordService { 35 private UserStorage storage; 36 private Map authKeys; 37 38 public PasswordService(UserStorage storage) { 39 this.storage = storage; 40 authKeys = new HashMap (); 41 } 42 43 public String getPassWordKey(User user) { 44 String key = Digest.getDigest(Integer.toString((new Random ()).nextInt())); 45 authKeys.put(key, user); 46 return key; 47 } 48 49 public User changePassWord(String key, String passwd) { 50 User user = (User) authKeys.get(key); 51 if (null != user) { 52 user.setPasswd(passwd); 53 storage.storageStore(user); 54 authKeys.remove(key); 55 } 56 return user; 57 } 58 } 59 | Popular Tags |