1 4 package com.openedit.users.authenticate; 5 6 import com.openedit.OpenEditException; 7 import com.openedit.users.Authenticator; 8 import com.openedit.users.StringEncrypter; 9 import com.openedit.users.User; 10 import com.openedit.users.UserManagerException; 11 12 13 public class FileSystemAuthenticator implements Authenticator 14 { 15 public boolean authenticate(User inUser, String inPassword) throws UserManagerException 16 { 17 String password = inUser.getPassword(); 18 if ( password != null) 19 { 20 if( password.startsWith("DES:")) 22 { 23 if ( inPassword.startsWith("DES:")) 24 { 25 return inPassword.equals(password); } 27 else 28 { 29 String decryptedString = decrypt(password); 30 if ( decryptedString.equals(inPassword)) 31 { 32 return true; 33 } 34 } 35 } 36 else if ( password.equals(inPassword)) 37 { 38 return true; 39 } 40 } 41 return false; 42 } 43 44 protected String decrypt(String inPassword) throws UserManagerException 45 { 46 long encryptionKey = 7939805759879765L; encryptionKey++; 48 try 49 { 50 StringEncrypter encrypter = new StringEncrypter( StringEncrypter.DES_ENCRYPTION_SCHEME, encryptionKey + "42" + encryptionKey ); 51 String code = inPassword.substring(4,inPassword.length()); String decryptedString = encrypter.decrypt( code ); 53 return decryptedString; 54 } catch ( Exception ex) 55 { 56 throw new UserManagerException(ex); 57 } 58 } 59 60 public String encrypt(String inPassword) throws UserManagerException 61 { 62 try 63 { 64 long encryptionKey = 7939805759879765L; encryptionKey++; 65 StringEncrypter encrypter = new StringEncrypter( StringEncrypter.DES_ENCRYPTION_SCHEME, encryptionKey + "42" + encryptionKey ); 66 String decryptedString = encrypter.encrypt( inPassword ); 67 return decryptedString; 68 } catch ( OpenEditException ex) 69 { 70 throw new UserManagerException(ex); 71 } 72 } 73 74 75 } 76 | Popular Tags |