Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Javascript Login (User Account)

    Hello, I have been working on a website for a while now and have started working on user created accounts for my javascript login. Here is the code for the login:
    <h3 align="center">
    Sign In</h3>
    <form id="Form1" onsubmit="login()">
    <p align="center"> User Name: <input type="text" id="userid"></p>
    <p align="center"> Password: <input type="password" id="pswrd"></p>
    <p align="center"><input type="submit" value="Login"/>
    <input type="reset" value="Cancel"/></p>
    </form>
    <script language="javascript">
    UNArray=["User1","User2","User3"]
    PWArray=["Password1","Password2","Password3"]
    function login(){
    for(i=0;i<=UNArray.length;i++){
    if(document.getElementById("userid").value==UNArray[i]){
    if(document.getElementById("pswrd").value==PWArray[i]){
    window.open("Home.html")
    }
    }
    }
    }

    Here is the code for the "Create An Account" page:
    <form id="form1">
    Your First Name: <input type="text" name="firstname">
    <br/>
    <br/>
    Desired Username: <input type="text" name="username">
    <br/>
    <br/>

    Email (Optional): <input type="text" name="Email">
    <br/>
    <br/>
    Password: <input type="password" name="password">
    <br/>
    <br/>
    <input type="submit" value="Submit">
    </form>

    Can Anyone help me with this? Thanks!

  • #2
    New Coder
    Join Date
    Dec 2011
    Posts
    67
    Thanks
    20
    Thanked 1 Time in 1 Post
    You can not use JavaScript to let people create acounts.
    PHP needs to be used.

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, I have downloaded PHP but have no idea of how to install it.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,299
    Thanks
    10
    Thanked 585 Times in 566 Posts
    Quote Originally Posted by UltimateCoder View Post
    You can not use JavaScript to let people create acounts.
    why not?
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #5
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you have enough time, I would also like to see what is wrong with this code. I added in some code to make a username appear when you move to the Home page, and a "Signed in as Guest" section if you move to the page without logging in. Here is the code:
    <script type="text/javascript">
    window.onload=showName
    function showName(){
    if(localStorage.getItem("DDragon_UserName")=="" || localStorage.getItem("DDragon_UserName")=="undefind"){
    document.getElementById("LoggedIn").innerHTML="Signed in as Guest"
    }
    document.getElementById("LoggedIn").innerHTML="<a href='"+localStorage.getItem("DDragon_UserName")+"Profile.html'>"+localStorage.getItem("DDragon_User Name")+"</a>"
    }
    function logout(){
    localStorage.setItem("DDragon_UserName","")
    }
    </script>

  • #6
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Wyatt78 View Post
    If you have enough time, I would also like to see what is wrong with this code. I added in some code to make a username appear when you move to the Home page, and a "Signed in as Guest" section if you move to the page without logging in. Here is the code:
    <script type="text/javascript">
    window.onload=showName
    function showName(){
    if(localStorage.getItem("DDragon_UserName")=="" || localStorage.getItem("DDragon_UserName")=="undefind"){
    document.getElementById("LoggedIn").innerHTML="Signed in as Guest"
    }
    document.getElementById("LoggedIn").innerHTML="<a href='"+localStorage.getItem("DDragon_UserName")+"Profile.html'>"+localStorage.getItem("DDragon_User Name")+"</a>"
    }
    function logout(){
    localStorage.setItem("DDragon_UserName","")
    }
    </script>
    Solved this!

  • #7
    Regular Coder Taro's Avatar
    Join Date
    Oct 2011
    Location
    Geraldton, Ontario
    Posts
    155
    Thanks
    1
    Thanked 1 Time in 1 Post
    Quote Originally Posted by rnd me View Post
    why not?
    Hello,

    PHP is server side scripting, so passwords are secure within the servers. JavaScript is more local, so passwords and accounts can be hacked more easily, being that they may be located within the source code of the webpage. But, it should be possible to make JavaScript harder to hack, like finding ways to encrypt source code frequently without accessibility violations.
    Last edited by Taro; 04-27-2012 at 01:18 AM.
    Element ID

    Webs Support Helper

    Your friendly neighborhood Taroman.

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,628
    Thanks
    0
    Thanked 648 Times in 638 Posts
    Quote Originally Posted by Taro View Post
    like finding ways to encrypt source code frequently without accessibility violations.
    The smallest JavaScript encryption script I have come across is about 5k when minimised. Without a server side scripting language you'd also need to manually encrypt all the page content before uploading - and redo everything when you spot a typo in the page.

    Using JavaScript encryption would then make the entire page inaccessible to anyone with JavaScript turned off - with the only solution being to provide the unencrypted version to anyone who turns off JavaScript.

    If you use anything other than proper encryption then all someone need do is view the script source to see how to bypass the login. The only way to avoid this is to use a server side script.
    Last edited by felgall; 04-27-2012 at 03:19 AM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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