Re: validation
Re: validation
- Subject: Re: validation
- From: Geoff Hopson <email@hidden>
- Date: Tue, 20 Jan 2004 19:01:22 +0000
It's a kinda sorta coding style, I guess. The key value coding stuff
looks for a method called someKey(), getSomeKey(), then an attribute
_someKey and probably one or two more combos.
It's good OO practice (IMHO) to declare your vars private, use an
underscore at the start to indicate it, and to provide public accessors
to the variable.
E.g
public class MyClass {
private String _myString;
...
public void setMyString(String str) {
_myString = str;
}
public String myString() {
return _myString;
}
}
This all becomes super dooper important when you put classes/components
in packages, since the scope of the variable is private outside a
package - therefore the only way to see it is either to make the
variable public, or to use the public API. The OO police will tell you
the latter is the correct way.
As a side note, anyone know how to get Eclipse to auto-generate method
names like the above, instead of set_myString and get_myString? Does
that 'Accessor' service on MacOSX work with Java and Eclipse?
Geoff
On 20 Jan 2004, at 11:49, Drew Thoeni wrote:
Jonathan,
A question on encoding the password. I'm saving mine using the hash
function. Is that considered sufficient?
Also, a newbie question. You have fields that start with "_", e.g.
_oldPassword. I have seen these mentioned in the WO logs on occasion
and am suspecting there is something different in how WO views and
handles say "oldPassword" and "_oldPassword". What is the significance
of the underscore?
thanks
Drew
On Jan 20, 2004, at 2:22 AM, Jonathan Fleming wrote:
From: Ken Foust <email@hidden>
To: Jonathan Fleming <email@hidden>
Subject: Re: validation
Date: Mon, 19 Jan 2004 23:06:41 -0700
quick question
I see no reference to saving to the database
like the following
therefore you would need somehow to bind on of the password fields
to the key that has the link to the database ?????
Yep. I didn't go into any of that because i presumed you were already
doing this. What you ask for was a method that could validate a user
input in a password textfield against another that is hidden...
anyhow here a breakdown of what happening here:
in your WOBuilder component (PasswordPreference) you have 3 password
textfields bound as so
CurrentPasswordField: WOPasswordField {
size = 10;
value = oldPassword;
}
PasswordField1: WOPasswordField {
size = 10;
value = password1;
}
PasswordField2: WOPasswordField {
value = password2;
size = 10;
}
Back in the java class the call to the database comes from this
statement:
String _oldPassword = (String)
valueForKeyPath("session.user.password");
this sits in your local varible of the method in code (hidden
basically) and then when the user enters the password that is current
in your database the code does a simple check with an if control to
check that all things are equal before running the rest of the code
so that the user can then renew or do whatever you want then to do.
Bare in mind this is very basic validation for passwords and user
logins you really need to step it up a gear and encode you passwords,
however, this is a very good starting point, once you've got this,
stepping it up a gear will be easier.
Jonathan :^)
EOEditingContext ec = session().defaultEditingContext();
ec.insertObject(newRegister);
System.out.println("Saving new User entry: " +
newRegister);
ec.saveChanges();
newRegister = new Admin();
On Jan 19, 2004, at 10:48 PM, Jonathan Fleming wrote:
This will help you:
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;
public class PasswordPreference extends WOComponent {
protected String oldPassword;
protected String password1;
protected String password2;
protected String _msg;
public PasswordPreference(WOContext context) {
super(context);
// revert changes
session().defaultEditingContext().revert();
}
/*
* actions
*/
public void change() {
String _oldPassword = (String)
valueForKeyPath("session.user.password");
// check the passwords match
if (_oldPassword.equals(oldPassword)) {
if (password1.equals(password2)) {
takeValueForKeyPath(password1,
"session.user.password");
session().defaultEditingContext().saveChanges();
_msg = "Your password has been changed";
} else _msg = "New passwords do not match";
} else _msg = "The Current password is incorrect";
}
}
Everything you need to do in your class is in this method strip out
as necassary or use as is.
HTH
Kind regards
Jonathan :^)
From: Ken Foust <email@hidden>
To: email@hidden
Subject: validation
Date: Mon, 19 Jan 2004 22:03:29 -0700
I have two password fields ie WOPasswordField one is the real
one and the other confirms
I am trying to validate one against the other and then save the
users password to the database.
The program builds and works fine it saves the password when I
try to validate this it won't build and complains it can't resolve
the variable "password" I have read all four leading books and
have come to the conclusion that they don't want anyone to know
how to do this!!
Any help would be appreciated
Thanks Ken
_______________________________________________
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.
_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger
_________________________________________________________________
Sign-up for a FREE BT Broadband connection today!
http://www.msn.co.uk/specials/btbroadband
_______________________________________________
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.
_______________________________________________
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.
--
Geoff Hopson
Objectology Ltd.
http://www.objectology.co.uk/
_______________________________________________
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.