password-getting-updated-on-db-even-without-any-change-on-the-grid

Questionspassword-getting-updated-on-db-even-without-any-change-on-the-grid
Hamid Yousefi asked 3 months ago

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,

3 Answers
Abu Ghufran Staff answered 3 months ago

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.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Abu Ghufran Staff replied 3 months ago

You can share the code at gist.github.com and share the link here OR email me at [email protected]

Igor Girao answered 2 months ago

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”]);

}

Hamid answered 2 months ago

thnaks :))

Your Answer

3 + 19 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?