473,396 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

php3 to php5 - DB module password/login

Hello I entered a password protection to an admin module for a database a few years back using php3 - now the server has migrated to 5 and it does not work anymore - have looked at php.net but do not really know where to start.

First page has:
Expand|Select|Wrap|Line Numbers
  1. <form method="post" action="ConnectDB.php3" name="connection" onSubmit="return verifChamp(document.forms[0])">
  2. <input type="text" name="login" size="20" maxlength="20">
  3. <input type="password" name="pass" size="20" maxlength="20">
  4.  <input type="submit" name="connect" value="Connecter">
  5. </form>

the second page : Connect DB.php3 has:
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $ok=0;
  3. if( isset ($conn) && $conn=="OK") {
  4.     $ok=1;
  5. }
  6. else {    
  7.  
  8. $u="Uxx";
  9. $p="yyy";
  10. $h="zzz";
  11.  
  12. mysql_connect($h,$u,$p);
  13.  
  14. $resPass=mysql(DBxx,"SELECT login, password FROM connection WHERE login = '$login' AND password = '$pass'");
  15. $nbPass=mysql_numrows($resPass);
  16.  
  17. if( $nbPass < 1 ) 
  18.     $ok=0;
  19. else
  20.     $ok=1;
  21. }
  22.  
  23. if( !$ok ) :
  24.  
  25. ?>
Any ideas where I can find the info or even better - where is it wrong..?

Very grateful for help.
Feb 6 '14 #1

✓ answered by Dormilich

for working with a DB, you’ll find something in the Manual’s PDO or MySQLi sections (note that the old mysql_* functions are deprecated).

your other problem—SQL Injection—there Google will provide a plethora of explanations.

depending of your exact version of PHP 5, you can make advantage of password hashing functions like password_hash(). generally, passwords should never be stored in plain text (a matter of security), therefore you should hash them.

since register_globals is now removed from PHP (another security matter), you fetch your user-supplied data from one of the superglobals (depending on your transfer method that would primarily be $_GET and $_POST).

short tags should not be used anyways, typing those three extra letters (i.e. <?php instead of <?) does not have any effect on performance.

the SQL query itself. since you only want to know, if there is a match or not, return the number of matches via SQL’s COUNT() function (PS. fetching data is more reliable that counting result rows). besides that, in SQL never request data you don’t need. therefore the SQL wildcard * is a no-go.
a sensible login query looks like
Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT(*) FROM mytable WHERE username = ? AND password_hash = ?;
tip: "connection" is a poor name for a table that stores user data (and not connections)

tip: make sure to set indexes on the DB table. makes the queries much faster


note: .php3 is a bad choice for a PHP 5 file extension. just the generic .php suffices.


javascript: event handlers should be defined inside JavaScript. doing that inside HTML makes it more complicated to read and maintain, and cuts down on possibilities.

e.g.
Expand|Select|Wrap|Line Numbers
  1. document.forms[0].addEventListener("submit", verifyChamp);
  2.  
  3. function verifyChamp(evt) 
  4. {
  5.     // note: the form element is in the variable 'this'
  6.  
  7.     // do validation
  8.  
  9.     // cancel submission if something is wrong
  10.     if (!valid) {
  11.         evt.preventDefault();
  12.     }
  13. }

4 1614
Dormilich
8,658 Expert Mod 8TB
if you’re switching from PHP 3 to PHP 5, I recommend a complete rewrite. so much has changed that simply applying some fixes won’t do it in the long run.
Feb 7 '14 #2
Thank you Support and Dormilich

Apologies about my incorrect way of posting.

D- I appreciate the suggestion. Any ideas where I can find and read up on a similar php5 function i.e. password to entering (and changing) a DB?
Feb 7 '14 #3
Dormilich
8,658 Expert Mod 8TB
for working with a DB, you’ll find something in the Manual’s PDO or MySQLi sections (note that the old mysql_* functions are deprecated).

your other problem—SQL Injection—there Google will provide a plethora of explanations.

depending of your exact version of PHP 5, you can make advantage of password hashing functions like password_hash(). generally, passwords should never be stored in plain text (a matter of security), therefore you should hash them.

since register_globals is now removed from PHP (another security matter), you fetch your user-supplied data from one of the superglobals (depending on your transfer method that would primarily be $_GET and $_POST).

short tags should not be used anyways, typing those three extra letters (i.e. <?php instead of <?) does not have any effect on performance.

the SQL query itself. since you only want to know, if there is a match or not, return the number of matches via SQL’s COUNT() function (PS. fetching data is more reliable that counting result rows). besides that, in SQL never request data you don’t need. therefore the SQL wildcard * is a no-go.
a sensible login query looks like
Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT(*) FROM mytable WHERE username = ? AND password_hash = ?;
tip: "connection" is a poor name for a table that stores user data (and not connections)

tip: make sure to set indexes on the DB table. makes the queries much faster


note: .php3 is a bad choice for a PHP 5 file extension. just the generic .php suffices.


javascript: event handlers should be defined inside JavaScript. doing that inside HTML makes it more complicated to read and maintain, and cuts down on possibilities.

e.g.
Expand|Select|Wrap|Line Numbers
  1. document.forms[0].addEventListener("submit", verifyChamp);
  2.  
  3. function verifyChamp(evt) 
  4. {
  5.     // note: the form element is in the variable 'this'
  6.  
  7.     // do validation
  8.  
  9.     // cancel submission if something is wrong
  10.     if (!valid) {
  11.         evt.preventDefault();
  12.     }
  13. }
Feb 7 '14 #4
Thank thank you thank you :) !! - now I got something to work from
Feb 7 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: thenetflyer | last post by:
<!-- The following sample should authorize the user to log on the site. This works once but after refreshing the browser, it does not prompt again for login until all browser (IE 6) windows are...
0
by: elektrophyte | last post by:
I'm developing a webapp that needs to track users and provide each user with a view of their own data. In other words, it goes beyond merely protecting certain areas of the site. The application...
5
by: Michele Petrazzo | last post by:
Is there a method for add a password to a file created by zip module? Thanks, Michele
9
by: Newbie! | last post by:
Hey does anybody know of anywhere where I can read up or download some exaples of setting up a multi user password system, using access? Ta Si
2
by: Yaa | last post by:
Hi guys! i need you to help me with a code for user login,and where a user will be able to change his/her password.
1
by: bhassel | last post by:
I'm running Access2003 connecting to Sybase via ODBC. Is it possible to embed a users password and login in the ODBC driver? If so how is it done? I've tried "LoginID", "LogPassword", "UserID",...
10
by: wayniac | last post by:
I was wondering if someone could tell me how to set up a screen. I have all of the account information entered into the database, but am not certain on how I am to insert it into a switchboard/form....
5
Death Slaught
by: Death Slaught | last post by:
I need to know how to make a username and password login screen for an online game that im making and i need it so i can access that person account and look at their password or edit their account so...
5
by: jmarcrum | last post by:
Hi everyone! I have a form that has two command buttons (Add, and Edit). If the user clicks Add, another form pops up asking for a username and password. If the user enters the username and...
0
by: EnricHilario | last post by:
Hello, I', trying to program the access to a https url, but I have a problem, because when I program to navigate the url-> objIExplorer.Navigate "https://edomus.tesa/", then appears a pop-up screen...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.