Encryption Code Problem
Encryption Code Problem
- Subject: Encryption Code Problem
- From: "Jonathan Fleming" <email@hidden>
- Date: Tue, 03 Jun 2003 03:12:01 +0100
Can anyone tell if I'm doing something wrong here. I had this working with
an OpenBase database but I've recently moved over to MSSQLServer2000 and now
can not get past my login possibly... no probably because my encryption code
is not encoding correctly. If I turn off the encryption code and enter a
normal text password i can get past the login as normal.
The problem i'm experiencing is that the code that saves to the database
seems to be slightly different to what is in the database.
this is the NSLog out print of the launcher:
m\tY? /-5iShT?g " uy
Although if I copy this to a text file or into the database it changes to
this:
m\tY?/-5iShT?g"uy
this is what's saved the database
m\tY?/-5iShT?g"uy
(the encryted text above may not print in HTML correctly so basically in the
NSLog where I'm getting spaces these are converted when saved to the
database with squares. If I use a tool like DBEdit to view the content of
the database I can see the spaces instead of squares. Again does this mean
anything?)
I don't think this is a problem but I could be wrong, or is it in the code i
use below?
In my business logic java file named TbControlPanel I have this:
import com.webobjects.foundation.*;
import com.webobjects.eocontrol.*;
import java.util.*;
import java.math.*;
import java.security.*;
import java.io.*;
public class TbControlPanel extends EOGenericRecord {
public TbControlPanel() {
super();
}
/*--------------- Business Logic ---------------*/
/*
* public static
*/
public static String encrypt(String plaintext) {
String encoding = "ISO-8859-1";
String ciphertext = null;
// one-way encryption algorithm
try {
MessageDigest messageDigest =
MessageDigest.getInstance("SHA-1");
byte[] bytes = plaintext.getBytes(encoding);
// encrypt
messageDigest.reset();
byte[] encryptedBytes = messageDigest.digest(bytes);
ciphertext = new String(encryptedBytes, encoding);
} catch (Exception exception) {
NSLog.err.appendln("Control Panel User: unable to encrypt
plaintext: " + plaintext);
}
return ciphertext;
}
public String password() {
return (String)storedValueForKey("password");
}
public void setPassword(String password) {
String encryptedPassword = encrypt(password);
NSLog.out.appendln("===\r Encypted password = ");
takeStoredValueForKey(encryptedPassword, "password");
}
==========================================
The login Form code sits in the Session java class
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.EOUtilities;
import java.io.*;
protected String password = null;
protected String username = null;
protected String loginName;
/*-------------------------------------------*/
public WOComponent login() {
NSMutableDictionary lookup = new NSMutableDictionary();
lookup.setObjectForKey(username.toLowerCase(), "loginName");
lookup.setObjectForKey(TbControlPanel.encrypt(password), "password");
EOEditingContext ec = defaultEditingContext();
NSArray result = EOUtilities.objectsMatchingValues(ec,
"TbControlPanel", lookup);
if (result.count() == 1) {
setUser( (TbControlPanel) result.objectAtIndex(0));
}
return null;
}
/*-------------------------------------------*/
In the database EOModel I have added to the connection dictionary
databaseEncoding: ISO Latin-1
The password column of the database & EOModel accepts 255 varchar, enough
i'm sure to cover the encrypted text
And that's about it
Any ideas?
Jonathan :^)
_________________________________________________________________
Find a cheaper internet access deal - choose one to suit you.
http://www.msn.co.uk/internetaccess
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.