The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP-General - New website, looking for registration code
Discuss New website, looking for registration code in the PHP Development forum on Dev Shed. New website, looking for registration code PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 27th, 2012, 09:32 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
Time spent in forums: 39 m 52 sec
Reputation Power: 0
|
|
|
PHP-General - New website, looking for registration code
Hello. I am new to PHP and I want to add something to a website that I will be opening. Basically, I want to be able to have a code that does not allow a user to have the same password as their username. Can anyone help me?
Thank you guys,
|

October 27th, 2012, 09:49 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 15
Time spent in forums: 3 h 49 m 21 sec
Reputation Power: 0
|
|
|
check this link for adding user and validating user.
://php.thedemosite.co.uk/addausercode.php
|

October 27th, 2012, 09:53 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Then find the places where users register and where they change their passwords, and in the validation parts add a check that their username isn't the same as the password.
|

October 27th, 2012, 10:00 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
Time spent in forums: 39 m 52 sec
Reputation Power: 0
|
|
|
thank you for the link. What I meant is the code that I add on registration page that prevent my customers to have a matching username and password.
Cheers
|

October 28th, 2012, 12:53 AM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 47
Time spent in forums: 11 h 51 m 3 sec
Reputation Power: 1
|
|
The easiest way to do this would be with JavaScript.
You can check out this page by W3C to find out more about form validation.
http://www.w3schools.com/js/js_form_validation.asp
Here's an example tailored to your need:
Code:
<html>
<head>
<title>
Example Page
</title>
<script type="text/javascript">
function validateForm() {
if (document.forms["myForm"]["username"].value == document.forms["myForm"]["password"].value) {
// Display notification
document.getElementById('notification').innerHTML = 'Your username and password must be different.';
// You must return false to avoide actual form submission
return false;
}
}
</script>
</head>
<body>
<span id="notification" style="color: red;"></span>
<form method="post" action="myfile.php" name="myForm" onsubmit="return validateForm()" >
<input type="text" name="username" id="username">
<input type="text" name="password" id="password">
<input type="submit" name="submit" id="submit">
</form>
</body>
</html>
Keep in mind...
You must also perform this check in your PHP POST script if you want to enforce it. If you *only* perform the check with JavaScript, the user could just disable JavaScript to bypass it. JavaScript is just a nice way to give the user some instant feedback.
|

October 28th, 2012, 06:08 PM
|
 |
Lost in code
|
|
|
|
|
What you're asking for isn't difficult to do; it just involves adding a simple if statement. It's really impossible to go into any more specific details without knowing exactly what your code looks like.
|

November 8th, 2012, 06:26 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
Time spent in forums: 39 m 52 sec
Reputation Power: 0
|
|
|
Okay. Thats make sense.
Thank you so much
|

November 27th, 2012, 07:53 AM
|
|
Contributing User
|
|
Join Date: Mar 2011
Posts: 121
Time spent in forums: 1 Day 53 m 21 sec
Reputation Power: 0
|
|
|
New website, looking for registration code [split]
hi
Please find the answer.
PHP Code:
<?php
include('config.php');
$userName=mysql_real_escape_string($_POST['user_name']);
$userPass=mysql_real_escape_string($_POST['user_password']);
$errors=array();
if($userName === $userPass){
$errors[]="Your UserName and Password must be different";
}
if(empty($errors)){
$query="insert query here...";
$result=mysql_query($query);
}else{
foreach($errors as $error){
echo $error.'<br>';
}
}
mysql_close();
?>
[[ "phpnet" tags are for references to the online manual. use "php" tags for PHP code --requinix ]]
Thanks
diya
Last edited by requinix : November 27th, 2012 at 02:21 PM.
|

November 27th, 2012, 02:22 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Quote: | Originally Posted by diyaots Please find the answer. |
How are we supposed to do that when we don't even know the question?
|

November 27th, 2012, 03:19 PM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
Hi,
if I understand him correctly, this is supposed to be a solution for the original thread.
|

November 27th, 2012, 03:44 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
...Damn. That does make sense.
Un-split 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|