Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Username and Password verification

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I am querying a table on two fields, Username and Password to validate a site log-on attempt. Is there a way of verifying that a record matches apart from running through a fetchrow_array() loop?

Keith
 
Check your recordset for EOF

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
audiopro:
If you issue a SELECT query like:

SELECT count(*) from credentials_table where username_column = 'usernamevalue' and password_column = 'password'

then only a single record will ever have to be retrieved.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
johnwm
Code:
[i]Check your recordset for EOF [/i]
I understand that reaching EOF would mean no matches found.
But how do I check the record set?

sleipnir214
Your code appears to populate my fetchrow_array() whatever the Username and Passwords Are.

This is the code I am using as a test and works ok but thought there may be a more elegant solution.
Code:
my $VALID=0;
while(@results=$sth->fetchrow_array()){
	++$VALID;
}
print "$VALID<BR>";
This will also flag duplicate username / filename combinations. New records are coded to prevent this but it could happen.

Keith
 
Yes, my query will always return a value.

That value will be a zero if no records match the user's credentials.

That value will be non-zero (ideally, exactly 1) if the user-supplied credentials are in the database.



The point of my post was to point out that with a correctly-written query, there should be no looping through returned records. Just fetching a value.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
If you use mysql_fetch_array(), the array returned will contain one element. That one element (index 0) will contain the number of records that match the user's supplied credentials.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top