-1
I am beginning to venture into the world of web programming and am having difficulties with the following subject: I’m creating a password exchange page. I would like my code to compare the login that the user is trying to change the password, with the login that is assigned in my Sesssion, converting the login to lowercase and then making the comparison.
<script>
function validar(){
var login = formlogin.nlogin.value;
var senha = formlogin.nsenha.value;
var novasenha = formlogin.novasenha.value;
var logado = "<?php echo $logado?>"
if (login != logado.toLowerCase()){
alert('Você não pode alterar a senha para este usuário.');
formlogin.nlogin.focus;
return false;
}
if (login == ''){
alert('Preencha o campo de login');
formlogin.nlogin.focus;
return false;
}
if (senha == ''){
alert('Preencha o campo de senha');
formlogin.nsenha.focus;
return false;
}
if (novasenha == ''){
alert('Preencha o campo Nova senha');
formlogin.novasenha.focus;
return false;
}
}
</script>
When I do the comparison, even with the string converted to lower case, I get the message that it is impossible to change the user.
Any hint?
Where did you come from
formlogin
?– Jéf Bueno
Where did this php syntax come from in the middle of js?
var logado = "<?php echo $logado?>"
– MarceloBoni
formlogin is the form name. $logged in is the php variable that contains the PHP $_Session username. It was the way I found to pass the value of the $_Session variable to javascript.
– Romeu Oliveira
you should do it on server code, in your case in
php
, imagine the password being displayed onhtml
and easy for anyone to see displaying page source code?– Ricardo Pontual
i put in javascript to put a pop-up warning... I will try to rewrite the code using only php.
– Romeu Oliveira
It is very dangerous for you to do this check in Javascript. Nowadays, anyone with basic knowledge can delete their checks through the "Inspect Element" function of the browser. As it comes to session, I advise you to do in your PHP script.
– Carlos Andrade
In your check the var logged in is being passed to lowercase while the var login remains without the same conversion, try to put it in your if login.toLowerCase()
– João Rener