Connecting Tech Pros Worldwide Forums | Help | Site Map

Form Authentication

gpo gpo is offline
Newbie
 
Join Date: Nov 2006
Posts: 6
#1: Jul 10 '07
I want to Authenticate a user form using struts and mysql, I've got the jsp,
Formbean ,but the mysql logic is problem .What's the solution on the sql side to check the user?

part code
__________________________________________________ ____________________________

<html:form action="/login">
<table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td colspan="2">

</td>
</tr>
<tr>
<td width="15%">Enter your name:</td>
<td width="85%">
<html:text property="name" size="25" maxlength="50"
onfocus="this.select()"/>
</td>
</tr>

Formbean code

public class LoginForm extends org.apache.struts.validator.ValidatorForm{

private String name = null;

private String result ;

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}



public void setResult(String result) {
this.result = result;
}

public String getResult() {
return result;
}

}

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Jul 12 '07

re: Form Authentication


Heya, gpo.

That all depends on how your data is organized. Traditionally, a User must provide a valid Username and Password. The password is (should!) always stored as an encrypted hash.

Ideally, your query will look something like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM `Util_Users` WHERE `username` = 'someName' AND `password` = MD5('somePass') LIMIT 1;
  2.  
Other popular encryption functions are SHA1() and CRYPT()
http://dev.mysql.com/doc/refman/5.0/...functions.html

For extra security, consider encrypting the password on the JSP side and passing the encrypted string to MySQL instead (that way, your Users' passwords won't be visible in log files).
Reply