Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-10-2012, 12:25 AM   PM User | #1
Wyatt78
New to the CF scene

 
Join Date: Feb 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Wyatt78 is an unknown quantity at this point
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!
Wyatt78 is offline   Reply With Quote
Old 02-10-2012, 09:58 AM   PM User | #2
UltimateCoder
New Coder

 
Join Date: Dec 2011
Posts: 67
Thanks: 20
Thanked 1 Time in 1 Post
UltimateCoder is an unknown quantity at this point
You can not use JavaScript to let people create acounts.
PHP needs to be used.
UltimateCoder is offline   Reply With Quote
Old 02-14-2012, 04:42 AM   PM User | #3
Wyatt78
New to the CF scene

 
Join Date: Feb 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Wyatt78 is an unknown quantity at this point
Thank you, I have downloaded PHP but have no idea of how to install it.
Wyatt78 is offline   Reply With Quote
Old 02-14-2012, 10:23 PM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by UltimateCoder View Post
You can not use JavaScript to let people create acounts.
why not?
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 02-19-2012, 02:53 AM   PM User | #5
Wyatt78
New to the CF scene

 
Join Date: Feb 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Wyatt78 is an unknown quantity at this point
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>
Wyatt78 is offline   Reply With Quote
Old 02-20-2012, 09:31 PM   PM User | #6
Wyatt78
New to the CF scene

 
Join Date: Feb 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Wyatt78 is an unknown quantity at this point
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!
Wyatt78 is offline   Reply With Quote
Old 04-27-2012, 01:16 AM   PM User | #7
Taro
Regular Coder

 
Taro's Avatar
 
Join Date: Oct 2011
Location: Geraldton, Ontario
Posts: 155
Thanks: 1
Thanked 1 Time in 1 Post
Taro is an unknown quantity at this point
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.
__________________
Element ID

Webs Support Helper

Your friendly neighborhood Taroman.

Last edited by Taro; 04-27-2012 at 01:18 AM..
Taro is offline   Reply With Quote
Old 04-27-2012, 03:17 AM   PM User | #8
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/

Last edited by felgall; 04-27-2012 at 03:19 AM..
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 12:41 AM.


Advertisement
Log in to turn off these ads.