1 16 17 package org.apache.cocoon.components; 18 19 import java.io.BufferedReader ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.io.InputStreamReader ; 23 import java.util.HashMap ; 24 import java.util.StringTokenizer ; 25 26 public class UserManager { 27 28 static UserManager instance; 29 30 HashMap passwords = new HashMap (); 31 HashMap names = new HashMap (); 32 33 protected UserManager(InputStream stream) throws IOException { 34 BufferedReader input = new BufferedReader (new InputStreamReader (stream)); 35 while (true) { 36 String line = input.readLine(); 37 if (line != null) { 38 if (!line.startsWith("#") && !line.equals("")) { 39 StringTokenizer st = new StringTokenizer (line,":"); 40 String name = st.nextToken(); 41 String password = st.nextToken(); 42 passwords.put(name,password); 43 String fullname = st.nextToken(); 44 names.put(name,fullname); 45 } 46 } else { 47 break; 48 } 49 } 50 } 51 52 public static UserManager getInstance(InputStream stream) throws IOException { 53 if (instance == null) { 54 instance = new UserManager(stream); 55 } 56 return instance; 57 } 58 59 public boolean isValidName(String name) { 60 return passwords.containsKey(name); 61 } 62 63 public boolean isValidPassword(String name, String password) { 64 String storedPassword = (String ) passwords.get(name); 65 return (storedPassword != null) && (storedPassword.equals(password)); 66 } 67 68 public String getFullName(String name) { 69 return (String ) names.get(name); 70 } 71 } 72 | Popular Tags |