Best way to save login data [closed]

0

Good afternoon, what would be the best way to save user login data? I have a login system in PHP that validates username and password via ajax and if everything is ok, I want to save the data (email in case) to be used elsewhere in the system. I thought about using session, but I do not think I can create / save a session with javascript, so I thought of localStorage but I do not think that would be safe. What would be the best way? I use PHP, jquery, ajax and javascript. Thankful.

    
asked by anonymous 26.10.2017 / 20:50

3 answers

1

In% validation of% you can already set the variables with the bank's data. I will make a very small example just to exemplify the use of the session, which saves the session in ajax

After validating the data in the database, save the name, login, and any other desired number in the%

session_start();
$_SESSION["codigo_usuario"] = $query[1];
$_SESSION["nome_usuario"] = $query[2];
$_SESSION["permissao"] = $query[3];
$_SESSION["email"] = $query[4];

And to retrieve the desired data you just have to call it, for example if you want to know the permission, just call the corresponding php .

$_SESSION["permissao"];

And when the user moves away from the system you destroy session with the command:

session_destroy();

In this way you can store the data of a session, do not use passwords in session, they can be captured if the encryption level is easy to break.

    
26.10.2017 / 21:17
0

The best way to save login (and the same used in several frameworks) is certainly the session. My projects laravel saves in session whenever a user logs in or out of the site.

A site that can clarify a better way to use the superglobal $ _SESSION [] will be in the references.

Proper use of sessions without the use of frameworks

    
26.10.2017 / 21:03
0

Friend I recommend using a framework in the back end, I am using Codeigniter in several projects, the framework itself takes care of the whole process of login, registration and authentication.

It already takes care of saving user data as well as maintaining a table called ci_sessions to save the sessions.

On top of this framework it is possible to build multiple applications, authenticating users in several different applications over the same database.

link

    
26.10.2017 / 21:04