KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > user > PasswordService


1 package org.snipsnap.user;
2
3 import org.snipsnap.snip.storage.UserStorage;
4
5 import java.util.Random JavaDoc;
6 import java.util.Map JavaDoc;
7 import java.util.HashMap JavaDoc;
8
9 /*
10  * This file is part of "SnipSnap Wiki/Weblog".
11  *
12  * Copyright (c) 2002-2003 Stephan J. Schmidt, Matthias L. Jugel
13  * All Rights Reserved.
14  *
15  * Please visit http://snipsnap.org/ for updates and contact.
16  *
17  * --LICENSE NOTICE--
18  * This program is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU General Public License
20  * as published by the Free SoftSware Foundation; either version 2
21  * of the License, or (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31  * --LICENSE NOTICE--
32  */

33
34 public class PasswordService {
35   private UserStorage storage;
36   private Map JavaDoc authKeys;
37
38   public PasswordService(UserStorage storage) {
39     this.storage = storage;
40     authKeys = new HashMap JavaDoc();
41   }
42
43   public String JavaDoc getPassWordKey(User user) {
44     String JavaDoc key = Digest.getDigest(Integer.toString((new Random JavaDoc()).nextInt()));
45     authKeys.put(key, user);
46     return key;
47   }
48
49   public User changePassWord(String JavaDoc key, String JavaDoc 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