I\’m mounting a grid from a User table where it is stored both the user, user name and last name, email, phone and the password. It\’s like a profile section. The user will be able to change his name, email and even the password. However, when the user perform a change only on the email address somehow the password get messed-up on the Database. Do you have any idea what is going on and how to prevent that ? Regards,
Hello,
I can tell only after reviewing the code.
My best guess is, It may happen if you have some database triggers set OR if you are using on_update event handler and have custom password logic there. Another possibility is, if you are storing hashed password, it may be getting rehashed on update.
You can share the code at gist.github.com and share the link here OR email me at [email protected]
Hello,
I created a function for this, see if it solves your problem.
WhatsApp Image 2024-10-01 at 09.24.29.jpeg
$e = array();
$e[“on_insert”] = array(“insert_md5”, null, true);
$e[“on_update”] = array(“update_md5”, null, true);
$g->set_events($e);
function update_md5($data){
global $g;
$xSql = “SELECT * FROM SEFAZ_USUARIOS WHERE ID = “.$data[“ID”];
$rs = $g->get_one($xSql);
$xId = $rs[‘ID’];
$xPass = $rs[‘PASSWORD’];
$xPassNew = $data[“params”][“PASSWORD”];
if ($data[“ID”] == $_SESSION[‘SEFAZ_ID’]){
if (($xPass == md5($data[“params”][“PASSWORD”])) || empty($xPassNew) ){
$data[“params”][“PASSWORD”] = $xPass;
} else {
$data[“params”][“PASSWORD”] = md5($data[“params”][“PASSWORD”]);
}
}else{
if (empty($xPassNew)){
$data[“params”][“PASSWORD”] = $xPass;
}else{
$data[“params”][“PASSWORD”] = md5($data[“params”][“PASSWORD”]);
}
}
}
function insert_md5($data){
$data[“params”][“PASSWORD”] = md5($data[“params”][“PASSWORD”]);
}