Skip to main content
May 16, 2007
Answered

Simple enough PHP/SQL Question

  • May 16, 2007
  • 3 replies
  • 368 views
I've made a page where the user signs up to something but I want to prevent them having the same password as their username. Whats the easiest way to do this? Do I do it through dreamweaver or SQL? I assume an IF statement with the conditioon kill or something along those lines will work, I really do not want values with the username and password repeated added to my database at all.

Thanks for the help, sorry it's such a newbie question :P
This topic has been closed for replies.
Correct answer Newsgroup_User
geschenk wrote:
> you could simply compare the submitted username & password field values using
> an IF-ELSE statement, and if the password equals the username, tell him
> something ;-) What�s your server model, PHP, ASP, CF ?

It says PHP in the subject line, so PHP it is.

if ($_POST) {
if ($_POST['username'] == $_POST['password']) {
$error = '<p>You cannot use your username as the password</p>';
}
else {
// Insert Record server behavior code goes here
}
}

In the form itself:

<?php if (isset($error)) echo $error; ?>

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

3 replies

Newsgroup_UserCorrect answer
Inspiring
May 16, 2007
geschenk wrote:
> you could simply compare the submitted username & password field values using
> an IF-ELSE statement, and if the password equals the username, tell him
> something ;-) What�s your server model, PHP, ASP, CF ?

It says PHP in the subject line, so PHP it is.

if ($_POST) {
if ($_POST['username'] == $_POST['password']) {
$error = '<p>You cannot use your username as the password</p>';
}
else {
// Insert Record server behavior code goes here
}
}

In the form itself:

<?php if (isset($error)) echo $error; ?>

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
May 16, 2007
Thanks David, that's basically what I was after, just wasn't sure the right way of doing it. Appreciate the help pal :)
Günter_Schenk
Inspiring
May 16, 2007
you could simply compare the submitted username & password field values using an IF-ELSE statement, and if the password equals the username, tell him something ;-) What´s your server model, PHP, ASP, CF ?
Inspiring
May 16, 2007
If, by SQL you mean SQL Server, and depending on what degree of SQL Server
functionality is available to you, then I would do this validation there.
Ideally, the best way to approach this in your database would be to add a
Unique Index accross these two columns, then in your SQL code check for
@@ERROR and build a return value into your code based on what @@ERROR
returns to you.

Hope this helps.


"slowpoke115" <webforumsuser@macromedia.com> wrote in message
news:f2dpub$4bd$1@forums.macromedia.com...
> I've made a page where the user signs up to something but I want to
> prevent
> them having the same password as their username. Whats the easiest way to
> do
> this? Do I do it through dreamweaver or SQL? I assume an IF statement with
> the
> conditioon kill or something along those lines will work, I really do not
> want
> values with the username and password repeated added to my database at
> all.
>
> Thanks for the help, sorry it's such a newbie question :P
>