This topic is locked
[SOLVED]

 Check Password existent

6/17/2010 11:46:36 PM
PHPRunner General questions
N
Nelson author

Hi,
After a while I came across this problem...I have many new users each day that register...and the problem is many register different items by the same email and exact same password...my login system is put on 'users can see and edit their own data only'...now those users who have many records come and log in...and only see one of their records...the rest will not appear on the page....what can I do to require a uniqe password..each time someone is saving a record..regardless of the e-mail...e-mail could stay the same..I wanna stop people from adding records over and over again with same password..is there a solution to this?
Nelson

A
ann 6/18/2010

Nelson,
use Before registration event and predefined action Check if specific record exists on the Events tab to check if the password already exists.

N
Nelson author 6/18/2010



Nelson,
use Before login event and predefined action Check if specific record exists on the Events tab to check if the password already exists.


Hi Ann,
I guess the best way to prevent users to add a record with the same password is to put this code on the Add page's 'before record added' event tab!

Am I right?
And if we say that the table's name is 'Ads' and the field names is Password...should I write the code like below?
and I guess I should put codes instead of these lines???
// if record exists do something
// if dont exist do something else

//********** Check if specific record exists ************

global $conn;

$strSQLExists = "select * from Ads where Password='Password'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

}

else

{

// if dont exist do something else

}
A
ann 6/18/2010

Nelson,
here is the correct code:

global $conn;

$strSQLExists = "select * from Ads where Password='".$values["Password"]."'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

}

else

{

// if dont exist do something else

}
N
Nelson author 6/18/2010



Nelson,
here is the correct code:

global $conn;

$strSQLExists = "select * from Ads where Password='".$values["Password"]."'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

}

else

{

// if dont exist do something else

}



Ann,
What should I write instead of "// if record exists do something" to prevent records from being added if the Password exist...right now it still adds new records with the same password?

A
ann 6/18/2010

Nelson,
to prevent saving of the record return false, otherwise return true.

Don't forget to delete this line at the end of the function:

return true;
N
Nelson author 6/18/2010



Nelson,
to prevent saving of the record return false, otherwise return true.

Don't forget to delete this line at the end of the function:

return true;



Ann,

Can I display a message in red below the password field saying: please choose another password, this password already exist
Otherwise they'll wonder why their records doesn't get added...and they wouldn't know how to fix it!
This is the the code that works:

global $conn;

$strSQLExists = "select * from Ads where Password='".$values["Password"]."'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

return false;

}

else

{

return true;

}
A
ann 6/18/2010

Nelson,
use $message variable of the function to display your message.

N
Nelson author 6/18/2010



Nelson,
use $message variable of the function to display your message.


Thanks Ann,
Problem solved!
Nelson