'hashing password to login. how can I join this?
I have a code for the login and a code for hassing the password, but dont know very well how to use them and to make them work in the server (how can I join them). Can some one please help me with this, making it work? it should be a register login to the web I'm making, I the password should be hashed. Can some one explain a bit what I have in the js (I found it on medium, but the post wasn't very explainatory and dont know how to use it but it might help someone.
login dot html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link rel="stylesheet" href="login.css">
<script defer src="login.js"></script>
</head>
<body>
<main id="main-holder">
<h1 id="login-header">Login</h1>
<div id="login-error-msg-holder">
<p id="login-error-msg">Invalid username <span id="error-msg-second-line">and/or password</span></p>
</div>
<form id="login-form">
<input type="text" name="username" id="username-field" class="login-form-field" placeholder="Username">
<input type="password" name="password" id="password-field" class="login-form-field" placeholder="Password">
<input type="submit" value="Login" id="login-form-submit">
</form>
</main>
</body>
</html>
hashing-server.js
const express = require("express");
const bodyparser = require("body-parser");
const bcrypt = require('bcryptjs');
const app = express();
app.use(bodyparser.json());
//create mysql connection
const mysql = require('mysql');
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'raja',
database: 'alead'
});
//define port
const port=3000;
app.get("/", (req, res) => {
res.json({message:'Root page'})
})
//login query example
app.get("/veify_password", (request, response) => {
const req=request.query
const query="SELECT password from user_master where username=?";
const params=[req.username]
connection.query(query,params,(err,rows) => {
if(err) throw err;
//
var output={}
if(rows.length!=0)
{
var password_hash=rows[0]["password"];
const verified = bcrypt.compareSync(req.password, password_hash);
if(verified)
{
output["status"]=1;
}else{
output["status"]=0;
output["message"]="Invalid password";
}
}else{
output["status"]=0;
output["message"]="Invalid username and password";
}
response.json(output)
});
})
//run the application
app.listen(port, () => {
console.log(`running at port ${port}`);
});
Solution 1:[1]
Amazon EC2 instances are just like normal computers. So, if you had a Windows computer on your desk and a Linux computer beside it, think about how you would copy files between the two computers and you can do the same thing with Amazon EC2.
Frankly, sending files 'to' a computer can be quite difficult due to security limitations and having to have some way of 'sharing' file systems, such as sharing a network drive.
A much easier way would be to have the Windows instance copy the files to an Amazon S3 bucket, and then have the Linux instance download the files from S3. You can easily copy the files by using the AWS Command-Line Interface (CLI).
This method avoids all the problems with security, sharing protocols and coping with different operating systems.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | John Rotenstein |
