TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 02-12-2008, 09:08 PM   #1 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 265
Thanks: 2
TlcAndres is on a distinguished road
Default Join

I was wondering if anyone could show me a data dump and a valid example of using JOIN

I wanted to see if I could use it to retrieve the sakt and use CONCAT and MD5 to hash up my passwords for loggin in.
TlcAndres is offline  
Reply With Quote
Old 02-12-2008, 10:50 PM   #2 (permalink)
The Acquainted
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 175
Thanks: 6
CoryMathews is on a distinguished road
Default

i didnt understand that say it again.
CoryMathews is offline  
Reply With Quote
Old 02-12-2008, 11:07 PM   #3 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 265
Thanks: 2
TlcAndres is on a distinguished road
Default

Lets us say for example you've the following

Table members
`id`
`username`
`password`

Table info
`info1`
`info2`
`user_id`

What would be a JOIN statement between the two? (I've looked at the examples on mysql and can't understand)

Ultimately I'd like to in the query fetch the hash from the row and concat it with the password and then md5 it.
TlcAndres is offline  
Reply With Quote
Old 02-13-2008, 03:55 AM   #4 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

So we're assuming the relation between the two tables is members.id ==> info.user_id? You might consider using `member_id` as the column name on both columns, it looks a bit ambiguous. I usually use naming conventions like members.memberID ==> info.memberID_FK to relate the two tables and make it clear the info table stores the Foreign Key.

Code:
SELECT
 m.username
, m.password
, i.info1
, i.info2
FROM members AS m
INNER JOIN info AS i
ON ( m.id = i.user_id )
WHERE m.id = 2;
I'd be happy to provide a 'real' JOIN with the CONCAT expression if you'd provide more detail on the columns and what output you expect.

Please post any questions you have as to the JOIN statement itself.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 02-17-2008, 04:24 AM   #5 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 265
Thanks: 2
TlcAndres is on a distinguished road
Default

I can't seem to wrap my head around it

SELECT `banned` , `password`
FROM `mrf_users`
INNER JOIN `mrf_uhash` AS `hash`
WHERE `user_idFK` =3 ON ( MD5( CONCAT( 'trick', `hash`.`hash` ) ) = `password` )


In this query I'm trying to retrieve the hash and then md5 the concated string and match it with the retrieved password, I'm aware it's syntactically so any pointers would be great.
TlcAndres is offline  
Reply With Quote
Old 02-17-2008, 06:32 PM   #6 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

You've got a couple of elements out of place, namely the ON conditional for the JOIN statement needs to immediately follow the JOIN. Then you can use a WHERE clause to establish more matches for the join statement to match columns on.

It needs to be something more like
Code:
SELECT `banned` , `password`
FROM `mrf_users`
INNER JOIN `mrf_uhash` AS `hash`
ON ( `mrf_users`.`password` = MD5( CONCAT('trick',`hash`.`hash`) ) )
WHERE `user_idFK` =3;
I don't quite understand the application logic, but I guess that's ok.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 02-17-2008, 07:04 PM   #7 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 265
Thanks: 2
TlcAndres is on a distinguished road
Default

Well the query is used for a login and simultaneous ban check, the final query is something supposed to fetch the hash from the table in accordance with the proper username, the concate it and md5 is and check whether it's the same as the password in the table mrf_users where the username is mrferos
TlcAndres is offline  
Reply With Quote
Old 02-17-2008, 07:15 PM   #8 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

Right, I was just not clear on why there were two hash values, i.e. a hash within an MD5 hash.

Did altering that query do it?
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 02-17-2008, 07:32 PM   #9 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 265
Thanks: 2
TlcAndres is on a distinguished road
Default

I'm terrible with naming convention, that hash within the md5 is actually a salt.
TlcAndres is offline  
Reply With Quote
Old 02-17-2008, 08:05 PM   #10 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

Aha. That makes sense.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 05:13 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0