0
I’m trying to insert Customers but with a password that is generated by a code but I’m not quite sure how to implement the use of this.
site.get("/processa_InsereCliente", function (req, res) {
// verificação se todos os atributos necessários foram preenchidos no formulário anterior
if (req.query.Nome_cliente && req.query.Morada_cliente && req.query.CP_cliente && req.query.Localidade_cliente && req.query.Telefone_cliente && req.query.Email_cliente && req.query.Profissao_cliente && req.query.NIF_cliente) {
var query = "INSERT INTO Clientes VALUES(null," + mysql.escape(req.query.Nome_cliente) + ',' +
mysql.escape(req.query.Password_cliente) +
"," + mysql.escape(req.query.Morada_cliente) + "," + mysql.escape(req.query.CP_cliente) + "," + mysql.escape(req.query.Localidade_cliente) +
"," + mysql.escape(req.query.Telefone_cliente) +
"," + mysql.escape(req.query.Profissao_cliente) +
"," + mysql.escape(req.query.Dn_cliente) +
"," + mysql.escape(req.query.NIF_cliente) + ")";
runQuery(query, function (result) {
if (result && result.affectedRows > 0) {
res.redirect('/');
} else {
res.redirect('/Assinatura')
}
});
} else {
res.redirect('/')
}
});
The page that inserts the clients fetches the data from a form on another page, and this part works, but the part of mysql.escape (req.query.Password_client) wanted it to be replaced by the variable generated by the following code:
<script>
function generatePassword() {
var length = 8,
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
Password = "";
for (var i = 0, n = charset.length; i < length; ++i) {
Password += charset.charAt(Math.floor(Math.random() * n));
}
alert(Password);
}
</script>
I don’t know if I’m doing the best or even the right way, but so far I haven’t been able to find similar to help me solve this problem.
Thank you for all your help!!
And what do you do with the value of
Password_cliente
? do not use and create only a password unrelated to what the client has entered?– Sergio
What I would do is create a random password that goes into the database, but then the user name and password are delivered to the user via pdf. I do not have a password entry field on the part of the user.
– user179018
Okay! Then just have
mysql.escape(generatePassword())
instead ofmysql.escape(req.query.Password_cliente)
right?– Sergio