LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-08-2017, 07:46 PM   #1
manolakis
Member
 
Registered: Nov 2006
Distribution: xubuntu
Posts: 464

Rep: Reputation: 37
Javascript log in


Hello,

I am trying to create a web page where a user can register and log in. I want to use a javascript function where before the page loads the function checks if the user is already logged in. If he/she has signed in a welcome message will appear. If not, the user will be asked for his username and password.
I would be really obliged if anyone could help me with this.

Thank you.
 
Old 05-08-2017, 07:55 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
That is probably not something that you want to do in javascript. As a practical matter, you cannot do anything in javascript until after the page has loaded.

In general, anything that runs on the client (javascript) can be hacked, broken, bypassed or modified by a malicious user.

What goes out to the client should have already been authenticated as necessary on the server, and the server should re-authenticate each and evey request before returning anything to the client. What goes to the client, authentication-wise, should only be non-forgable identifying tokens.

Last edited by astrogeek; 05-08-2017 at 07:58 PM. Reason: typos, grammar, thoughts
 
1 members found this post helpful.
Old 05-08-2017, 07:56 PM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,224

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
This is not possible to do without server-side code.
 
1 members found this post helpful.
Old 05-08-2017, 08:09 PM   #4
manolakis
Member
 
Registered: Nov 2006
Distribution: xubuntu
Posts: 464

Original Poster
Rep: Reputation: 37
Hello,

Thanks for your replies. To be more clear with my description I want to make it look like exactly like as the linuxquestions log in form.
As you said I will need server-side code to do that. The server ideally will open an sql database, check for the username and password and reply to the client.
Because I do not have a lot of experience with javascript can someone can give some example code, especially how the server-side code would look like.

Thanks again.
 
Old 05-08-2017, 08:22 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Although not really complex, that is a question with many possible answers.

You almost certainly want to use PHP as the scripting language and MySQL as the database.

Rather than try answer it piece-wise, I did a search for 'php mysql login example' and found quite a few hits that looked useful.

This one, PHP Login and Registration Script with MySQL Example appears on first look to be simple but complete, well written and covers everything from the PHP code to the MySQL database table and queries. It is probably a good place to start.

I would suggest that you try to work through the example there, and maybe look for others that suite your reading style. Then if you encounter problems implementing your own you will be able to ask specific questions and we will be able to provide more useful answers.

Let us know how that works out for you!
 
1 members found this post helpful.
Old 05-12-2017, 05:04 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Often, client-side code is simply trusting. It checks for the existence of a cookie that is known to be furnished by the host when the user successfully logs in. (This cookie-value often includes the account-name of the user, in clear text, or provides this as some other cookie's value.) If the JavaScript finds this cookie, and is able to split-apart its value as described, it simply "acts accordingly, and hopes for the best." If not, it presents that the user is "not yet logged-in."

And, typically, this is "good enough."

Last edited by sundialsvcs; 05-13-2017 at 07:57 AM.
 
Old 05-12-2017, 05:21 PM   #7
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,224

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
From astrogeek's link:

Code:
if(mysqli_query($con, "INSERT INTO users(name,email,password) VALUES('" . $name . "', '" . $email . "', '" . md5($password) . "')")) {
Like many newbie PHP tutorials, it leads you into creating production websites with critical, and I mean critical, security vulnerabilities. This is not a topic for which "go google it" is the right answer.
 
2 members found this post helpful.
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: JavaScript creator Eich's latest project: KILL JAVASCRIPT LXer Syndicated Linux News 0 06-18-2015 08:30 AM
In Apache server, How to change log file location and log format for access log fil? since1993 Linux - Server 1 08-19-2009 04:14 PM
javascript enabled browser command log file logfile secretlydead Linux - Networking 1 06-26-2007 05:48 PM
Ubuntu Edgy/Firefox 2/Javascript - Firefox closes accessing websites with Javascript Interdictor Ubuntu 8 11-02-2006 11:58 AM
Opennms Logs - where are web.log, web_rtc.log and webauth.log referenced? not_much_of_a_guru Linux - Networking 0 07-12-2006 10:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration