CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2006
    Posts
    228

    [RESOLVED] Javascript Login

    Hello,

    I am trying to create login form

    however I want to make it when the user clicks the login button I want what ever the user types in as the username and password to appear in the URL.

    For Example:
    Login page = login.htm
    username = username
    password = password

    and I want it to look like this in the URL address:
    login.htm?user=username&pass=password

    I have done the following code so far:

    Code:
    <form action="login.htm" method=POST>
    
    Username <input type=text name=user size="20"><br />
    Password <input type=password name=pass size="20">
    <input type=submit value="Login"><p>
    </form>
    and now im stack, I don't know how to put the username and password in the url as well.

    can anyone help me out?

    Thanks

  2. #2

    Re: Javascript Login

    You really don't want to do this - putting a username / password into a URL doesn't provide any sort of security and can cause you issues with caching servers (even transparent ones), log files, etc.

    That said, if you must do this, change your form method to GET. This forces the form parameters to be sent as a query string. But again, this is not a smart way to do this.

  3. #3
    Join Date
    Mar 2006
    Posts
    228

    Re: Javascript Login

    Thanks it works just like how i want it to.

    I know its a security issue but I am designing my own server and i needed a way to send the username and password to it using the URL.

    Thanks heaps.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Javascript Login

    Why would you ever do that? If you are designing your own server...make it able to fetch the username and password in another manner. Any network packet sniffer would harvest these usernames and passwords in seconds.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: [RESOLVED] Javascript Login

    user/password should never be passed via url, less to an html file to process.

    - use POST method;
    - use somekind of server side class to process/validate the parameters;
    - only then respond with a html

    html:
    HTML Code:
    <!-- java version -->
    <form action="login.jsp" method="post">
       <fieldset>
          <input type="text" maxlength="10" name="user" />
          <input type="password" maxlength="10" name="pwd" />
       </fieldset>
    </form>
    
    <!-- php version -->
    <form action="login.php" method="post">
       <fieldset>
          <input type="text" maxlength="10" name="user" />
          <input type="password" maxlength="10" name="pwd" />
       </fieldset>
    </form>
    java solution:
    Code:
    <%
    String user = request.getParameter("user");
    String pwd = request.getParameter("pwd");
    //then you do what you need to valudate em
    %>
    php solution:
    PHP Code:
    <?php
    $user 
    $_REQUEST["user"];
    $user $_REQUEST["pwd"];
    //same here
    ?>
    If you are new to programming and server configurations I'd suggest php approach: easier to install the server, quicker to test, lots of tutorials in the web.
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

  6. #6
    Join Date
    Mar 2006
    Posts
    228

    Re: [RESOLVED] Javascript Login

    Hello,

    Thanks for the code.

    I am creating a server using Visual Basic 6.0

    When a user requests the page the program which im creating will send that page to the user.

    I am creating a custom page feature where it allows me to send a fake page to the server and the software will send a cutom page back to the user.

    I know that its a security issue but the page where the login is does not link to another page. So when a user logs in the software will read the login data and that is all.

    The login details never go another page even knowing there is page in <form action="login.jsp" method="post"> part of the script.

    When you click the submit button it will go an try and request the page but the server software which im writing will know its trying to load that page and will create a fake page for the user as each users details will be different.

    I would do this another way if anyknow knows how to connect to a IP and port and send data to that connection and well as reading the data from the connection. Since I don't know how I have to write this mini server that can connect to an IP and send data.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured