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
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-20-2008, 03:21 AM   #1 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Help Need some help, and i have got some questions to ask as well.

So i will start of with saying thank you to everyone who has helped me before and who will help out, and i will try to help out as much as i can. So for the question part. i was thinking what is the best way to secure an account i mean password and so on.

like password salt?
and stuff like that, i am
still a bit fuzzy on the part where you secure the password.
So all the help i can get is really appreciated.

And then i would need some help on why this is not working

i get this
print "You're account was made!";
but noting appears in the db.


PHP Code:
<?php
include 'config.php';
if(isset(
$_POST['submit']))
{

$username $_POST['username'];
$password $_POST['password'];
$email       $_POST['email'];
$referral $_POST['referral'];

      if(
strlen($username)<1
    {
        echo 
"You forgot to put in a username!";
    }
    
    if(
strlen($password)<1
    {
        echo 
"You Forgot to put in a password!";
    }
    
     if(
strlen($email)<1
    {
        echo 
"You did not put in you're email!";
    }
    
    else
    {
        if(
preg_match('/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/'$email))
        {
            
$query=( "INSERT INTO user (id, username,password,email,rank,referral,joined,ip) VALUES ('$id','$username',password('$password'),'$email','Normal','$referral',NOW(),'$ip')");
            
mysql_query($query) or die(mysql_error());
        }
        
    else 
    {
            
         print 
"You're account was made!";
            
    }
  }
}
else 
{
         echo 
"<form action='register.php' method='post'>",
         
"Please do mix, you're password with letters and numeric characters.</br>",
         
"Username:",
         
"<input type='text' name='username' size='15'/></br>",
         
"Password:",
         
"<input type='password' name='password' size='15'/></br>",
         
"Email:",
         
"<input type='text' name='email' size='15'/><br/>",
         
"Referral:",
         
"<input type='text' name='referral' size='15'/></br>",
         
"<input type='submit' name='submit' value='submit'/></form>";    
}


?>

Thank you in advance!
Code;Freek!
codefreek is offline  
Reply With Quote
Old 10-20-2008, 06:17 AM   #2 (permalink)
The Contributor
 
awuehr's Avatar
 
Join Date: Oct 2008
Location: Nuremberg, Germany
Posts: 26
Thanks: 3
awuehr is on a distinguished road
Default

Hi cf,

your if-else block at the regex-thingy says: If the regex matches, do something in your Db, if not, output 'Your account was made'. I don't know if that is what you want your script to do.

Please filter your $_POST values, don't use them unfiltered in SQL statements. It's very dangerous(SQL-Injection).


Greetings,

Alex
Send a message via ICQ to awuehr Send a message via Skype™ to awuehr
awuehr is offline  
Reply With Quote
Old 10-20-2008, 11:17 AM   #3 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

A good thing for storing passwords is to encrypt them and to use a salt with that like you said. An example would be

Quote:
$salt = "Some short string here";
$password = md5( $salt . sha1($password));
So then when you create the account you would use this on the password before inserting it to the db, as well as when that user logs in. This way their password is always encrypted, providing more security.
CoryMathews is offline  
Reply With Quote
The Following User Says Thank You to CoryMathews For This Useful Post:
codefreek (10-20-2008)
Old 10-20-2008, 01:59 PM   #4 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

awuehr, filter whit what?
codefreek is offline  
Reply With Quote
Old 10-20-2008, 02:09 PM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

You could try mysql_real_escape_string. Although if you wanted to take it further, you could filter depending on what you're expecting the data to be. Integer, string, et cetera...
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
codefreek (10-20-2008)
Old 10-20-2008, 02:43 PM   #6 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

i tried this but it wont work ? should i maybe do a check if the preg_match is valid by turning it into a var, and then running a check or how should i do it :S
Thank you!

PHP Code:
if(preg_match('/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/'$email))
        {
            
$query=( "INSERT INTO user (id, username,password,email,rank,referral,joined,ip) VALUES ('$id','$username',password('$password'),'$email','Normal','$referral',NOW(),'$ip')");
            
mysql_query($query) or die(mysql_error());
        
        }
        
        else 
        
            {
                
            echo 
'Not a valid email!';
            
            }
                    
         else
            
            {
                echo 
'Your account was made!';
                
            }
             
          }
     }

codefreek is offline  
Reply With Quote
Old 10-20-2008, 02:58 PM   #7 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

i tried this, but it wont input anything to the db :S


PHP Code:
if(preg_match('/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/'$email))
        {
            
$query=( "INSERT INTO user (id, username,password,email,rank,referral,joined,ip) VALUES ('$id','$username',password('$password'),'$email','Normal','$referral',NOW(),'$ip')");
            
mysql_query($query) or die(mysql_error());
        
            print 
"your account was made!";
        }
        
        else 
        
            {
                
            echo 
'not valid email!';
            
            }
                    
       
             
          }
     } 
codefreek is offline  
Reply With Quote
Old 10-20-2008, 07:51 PM   #8 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

i made a new pattern but i get ? insted of @ ;/
help..

PHP Code:
/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*\@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/ 
codefreek is offline  
Reply With Quote
Old 10-20-2008, 10:07 PM   #9 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

omg, what a noob mistake ! ;P forgot to set a set on the db
working now thank you ;)
codefreek is offline  
Reply With Quote
Old 10-20-2008, 11:03 PM   #10 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

why do i get error on this ?

PHP Code:
        $sql printf("    INSERT INTO
            `users`
        SET
            `username` = '%s',
            `password` = '%s',
            `email` = '%s',
            `rank` = 'normal',
            `referral` = '%s',
            `joined` = NOW()"
,

        
mysql_real_escape_string($username),
        
mysql_real_escape_string($password),
        
mysql_real_escape_string($email),
        
mysql_real_escape_string($referral)); 
codefreek is offline  
Reply With Quote
Old 10-20-2008, 11:11 PM   #11 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

using % instead of $ if those are variables.
CoryMathews is offline  
Reply With Quote
Old 10-20-2008, 11:27 PM   #12 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

don't follow :S
codefreek is offline  
Reply With Quote
Old 10-21-2008, 12:15 AM   #13 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Fixed Thank you!
codefreek is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 01:16 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design