#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Creating a Login and Registation Page


    I'm currently in the process of making a Registration and Login Page. My first page asks you if you want to create an account or login. What we have to do is take the information from the form that the user enters information into, and place it into a text file. I've got this working roughly. I understand that this is not good practice for security reasons, but this is an assignment for class and I MUST put the information into the text file. I have the information going into the text file, however I am having trouble comparing the posted username to all of the usernames inside of the database. Here is my code for the newaccount.html page, and the register.php file that the form submits to.



    newaccount.html:



    Code:
        <html>
    
        <head>
    
        </head>
    
        <body>
    
        <h3>Hello new user! Choose a user name and password ^_^</h3><br>
    
     
    
        <form action = "register.php" method = "POST" >
    
        Username: <input type = "text" name = "username"><br><br>
    
        Password: <input type = "password" name = "pass"><br>
    
        <input type = "submit" value = "Create Account" name = "submit"><br>
    
        </form>
    
        <form method = "LINK" action = "Proj2_practice.html">
    
        <input type = "submit" value = "Home Page" name = "submit2">
    
        </form>
    
     
    
        </body>  
    
     
    
     
    
     
    
        </html>










    register.php:








    PHP Code:
    <?php

     

    $username 
    $_POST['username'];

    $password $_POST['pass'];

     

    $userAndPass $username.",".$password;

     

    $userNames 'usernames.txt'." ";

    $passwords 'passwords.txt'." ";

     

    $fh_users fopen($userNames'a+')or die("sorry, we couldnt open the file");

    $fh_passwords fopen($passwords'a+')or die("sorry, we couldnt open the file");

     

    fwrite($fh_users$username." ");

    fwrite($fh_passwords$password." ");

     

    $allUserNames fread($fh_usersfilesize('usernames.txt'));

     

    echo 
    $allUserNames;

     

     

    ?>


    The usernames and passwords are being sent to the text files correctly, At the end of the code, it is not echoing the variable. As of right now, there is no information in the text files, I don't know if that is the reason that nothing is being echoed. Is my approach correct here? What I'm trying to do here is send each name and password to a username and password text file.Then, Im planning on

    exploding each of those text files by a space between them, which is why I add one after writing them to the text file, and then comparing the usernames and the passwords by their respective array elements. Am I overcomplicating this as much as I think I am? Please share your comments with me, I'm just trying to get better ^_^



    Thank you in advance!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,497
    Rep Power
    594
    For one thing, you never close the output files before trying to read. For another, I am wondering why you are doing it this unsecure way when there are already secure ways built-in?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    For another, I am wondering why you are doing it this unsecure way when there are already secure ways built-in?
    "this is an assignment for class" is a get out of jail free card for bad design.

    You seem to be adding an extra space to the end of your text file names. This isn't related to your problem though.

    Try adding fseek($fh_users, 0) before your call to fread. Don't call it before fwrite though or you will overwrite your file.

    Also file_get_contents is a better way to read the whole contents of a file into a variable.

    I'm not quite sure what gw1500se means about closing the output files before trying to read. You wouldn't want to call fclose on the handle before fread or it will error out.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,497
    Rep Power
    594
    For a sequential file I meant close it after write then open it for read. I've had bad luck with fseek in the past so I never use it.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo