Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help Login and Password
Old 05-14-2005, 06:40 AM Help Login and Password
Novice Talker

Posts: 6
Trades: 0
<?php
$username=$_POST['username'];
$username=trim($username);
$pass=$_POST['pass'];
$pass=trim($pass);

if (empty($username) || empty($pass))
{
echo "Please enter valid Username and Password";
exit;
}

if (!ereg("^[a-zA-z0-9]*$",$pass))
{
echo("password must contain only letters and numbers");
exit;
}
if (strlen($pass)!=8)
{
echo "Your password must be 8 characters long";
exit;
}


if (ereg("^s",$username))
{
$arrayuserpass=file("studentuserpass.txt");
for($i=0;$i<count($arrayuserpass);$i++)
{
$token=explode(",",$arrayuserpass[$i]);
$user=$token[0];
$psw=$token[1];
echo $username;
echo $user;
echo $pass;
echo $psw;

if ($username==$user)
{
if ($pass == $psw)
{
//$login="true";
echo "Login Sucessfull";
exit;
{
}
else
{
$login="false";
}
}
if ($login=="false")
{
echo "Username and Password not match";
}
}

?>




---- it keeps saying the password not match.. can someone help me. thanks
xopetz is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-14-2005, 06:55 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
use echo $psw; and echo $pass; every time you change something to them and see where your problem is ...

i got this when testing your code:
error, unexpected T_ELSE in D:\c_webserver\htdocs\teste\Untitled.php on line 47
afetr i removed the extra "{" :
error, unexpected $end in D:\c_webserver\htdocs\teste\Untitled.php on line 58
added a } before the script ended and it seemed to work ...
replaced the _POST with _GET to test it .... : "Login Sucessfull" ...
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 07:58 AM
Novice Talker

Posts: 6
Trades: 0
hi there.. thanks for he quick replied. i need to use "POST" coz im getting the data from a file. thanks for help
xopetz is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 08:04 AM
Novice Talker

Posts: 6
Trades: 0
the new php files after i made some changes
PHP Code:
<?php
    $username
=$_POST['username'];
    
$username=trim($username);
    
$pass=$_POST['pass'];
    
$pass=trim($pass);

    if (empty(
$username) || empty($pass))
    {
        echo 
"Please enter valid Username and Password";
        exit;
    }

    if (!
ereg("^[a-zA-z0-9]*$",$pass))
    {
        echo(
"password must contain only letters and numbers");
        exit;
    }
    if (
strlen($pass)!=8)
    {
        echo 
"Your password must be 8 characters long";
        exit;
    }


    if (
ereg("^s",$username))
    {
        
$arrayuserpass=file("studentuserpass.txt");
        for(
$i=0;$i<count($arrayuserpass);$i++)
        {
            
$token=explode(",",$arrayuserpass[$i]);
            
$user=$token[0];
            
$psw=$token[1];
            echo 
$username;
            echo 
$user;
            echo 
$pass;
            echo 
$psw;

            if (
$username==$user)
            {
                if (
$pass == $psw)
                {
                    
//$login="true";
                    
echo "Login Sucessfull";
                    exit;
                }
            }
            else
            {
                
$login="false";
            }
        }
        if (
$login=="false")
        {
            echo 
"Username and Password not match";
        }
    }

?>

Last edited by 0beron; 05-14-2005 at 08:50 AM..
xopetz is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 08:52 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Just to point out that you can use the [php ] [/php ] tags (without the spaces) to get a nicely framed and syntax coloured version of your code like above.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 05-14-2005, 10:41 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
xopetz: does it work now?

and by _POST and _GET i meant i replaced them when testing because i had no form and was lazy ... still if it worked with _GET it should work with _POST... (if you took care of the errors i posted above that is).
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 12:30 PM
Novice Talker

Posts: 6
Trades: 0
hi there..

the problem i had is the get doesnt work ( the password seems doesnt match ) i tried did what you explained above but still doesnt work. or i misunderstood what u were trying to say to me ? thanks for your help.

cheers
xopetz is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 12:41 PM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
you don't have to use $_GET i used it only for testing.

anyway, i didn't seem to be able to explain myself to good so i made my best to find your bug.

seems to me " if (ereg("^s",$username)) " should be negated " if (!ereg("^s",$username)) "

that way i got a login succesfull.
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-14-2005, 06:35 PM
Logical Program's Avatar
Super Talker

Posts: 130
Location: Atlanta, Georgia
Trades: 0
One more thing...
Your regular expression has [a-zA-z0-9] when it SHOULD be [a-zA-Z0-9].

(That period is not a "special character" for the RegEx; merely the end of my sentence. :-P)
__________________

Please login or register to view this content. Registration is FREE
- For all of your website programming and design needs, make the logical choice. Logical Assistance For Real-World Clients.
Logical Program is offline
Reply With Quote
View Public Profile Visit Logical Program's homepage!
 
Old 05-14-2005, 09:45 PM
Novice Talker

Posts: 6
Trades: 0
hi there. thanks for the help.
another thing is.

if ($username==$user)
{
if ($pass == $psw)
{
//$login="true";
echo "Login Sucessfull";
exit;
}
}
else
{
$login="false";
}
}


if ($pass == $psw) --> this line when i type the password correctly, it still return false. i dunno what happened. thanks


cheers,
xopetz is offline
Reply With Quote
View Public Profile
 
Old 05-15-2005, 04:30 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
i really have no clue why you say that it is not working, here are the files i tested them on. i had no problem whatsoever. check your form and your studentuserpass.txt please, your problem may lay there.


script.php :

PHP Code:
<?php
    $username
=$_POST['username'];
    
$username=trim($username);
    
$pass=$_POST['pass'];
    
$pass=trim($pass);

    if (empty(
$username) || empty($pass))
    {
        echo 
"Please enter valid Username and Password";
        exit;
    }

    if (!
ereg("^[a-zA-z0-9]*$",$pass))
    {
        echo(
"password must contain only letters and numbers");
        exit;
    }
    if (
strlen($pass)!=8)
    {
        echo 
"Your password must be 8 characters long";
        exit;
    }


    if (!
ereg("^s",$username))
    {
        
$arrayuserpass=file("studentuserpass.txt");
        for(
$i=0;$i<count($arrayuserpass);$i++)
        {
            
$token=explode(",",$arrayuserpass[$i]);
            
$user=$token[0];
            
$psw=$token[1];
            echo 
$username "<br>";
            echo 
$user "<br>";
            echo 
$pass "<br>";
            echo 
$psw "<br>";

            if (
$username==$user)
            {
                if (
$pass == $psw)
                {
                    
//$login="true";
                    
echo "Login Sucessfull";
                    exit;
                }
            }
            else
            {
                
$login="false";
            }
        }
        if (
$login=="false")
        {
            echo 
"Username and Password not match";
        }
    }

?>
form :

HTML Code:
<html>
<body>
<form name="form1" method="post" action="script.php">
  <input type="text" name="username">
  <input type="text" name="pass">
  <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
studentuserpass.txt :

Code:
username,password
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-15-2005, 11:53 AM
Novice Talker

Posts: 6
Trades: 0
thanks. it seems work perfectly. thanks
xopetz is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help Login and Password
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34407 seconds with 12 queries