0
Good morning,
I need to create a function that validates the client fields and compares to check if they are correct if they are, generate a temporary password.
Follow my code below.
function _gerar_senha_validando_campos(){
if (!empty($this->data['Cliente']['codcontrato']) && !empty($this->data['Cliente']['cpf_cnpj']) && !empty($this->data['Cliente']['login']) && !empty($this->data['Cliente']['ip'])) {
$cliente = $this->Cliente->find(array('situacao'=>'APR', 'codcontrato' => $this->data['Cliente']['codcontrato']));
if (($this->data['cliente']['codcontrato'] == $cliente['cliente']['codcontrato']) &&
($this->data['cliente']['cpf_cnpj'] == $cliente['cliente']['cpf_cnpj']) &&
($this->data['cliente']['login'] == $cliente['cliente']['login']) &&
($this->data['cliente']['ip'] == $cliente['cliente']['ip'])) {
$CaracteresAceitos = 'acefghijrsuxz23456789';
$max = strlen($CaracteresAceitos)-1;
$password = null;
for($i=0; $i < 8; $i++) {
$password .= $CaracteresAceitos{mt_rand(0, $max)};
}
return $password;
$this->set('sucesso', 'Senha alterada com sucesso!');
$this->set('newAviso','ATENÇÃO: Sua senha é temporária e vai expirar-se em 2 horas. Você deverá efetuar a troca da senha no site da Virtual Telecom ou clicando AQUI.');
}
if (($this->data['cliente']['codcontrato'] != $cliente['cliente']['codcontrato'])) {
$this->set('erro', 'Código do contrato inválido!');
}
if (($this->data['cliente']['cpf_cnpj'] != $cliente['cliente']['cpf_cnpj'])) {
$this->set('erro', 'CPF inválido!');
}
if (($this->data['cliente']['login'] != $cliente['cliente']['login'])) {
$this->set('erro', 'Login inválido!');
}
if (($this->data['cliente']['ip'] != $cliente['cliente']['ip'])) {
$this->set('erro', 'IP diferente do cadastrado!');
}
else{
$this->set('erro', 'Dados não conferem! Favor Verificar novamente');
}
}
else{
$this->set('erro', 'Campos obrigatórios não preenchidos');
}
}
Could you be more clear about the problem, doubt or path you want to take yourself? Would this temporary password be sent by email or shown on the same screen? If so, sending passwords by email (as plain text), is not good practice. But anyway better specifies the purpose of the question please.
– Renato Gonçalves
This password will be generated on the user screen, basically when the user enters the data, I want to check if the entered data is correct, if they are will generate an Alert stating ( password successfully changed! your password is $password ) Please make the password as it will be valid for two hours.
– Eduardo Santos
I have a view that the user passes the information to validate the data if the same forget the password. but to generate a new password the user has to confirm his data, being ok the system will generate a temporary password for the same, with this the user will access with this password and make the exchange in the system later.
– Eduardo Santos
Right, first the
return $password
shall end last.– Renato Gonçalves
Could you show me answering and exemplifying in the code please?
– Eduardo Santos
As soon as I have time, I’ll do it
– Renato Gonçalves