How to apply MD5 or SHA2 to a field

You can do this on client-side using a javascript MD5 library during a submit event such as "jqGridAddEditBeforeSubmit". See a list of full events here 

First Method: Javascript

A popular javascript MD5 library 

Follow the event handler example

Pseudo code:

$beforeSubmit = <<<BEFORESUBMIT
function (postdata, formid)
{
    postData.password = md5(postData.password);
    return return[true,''];
}
BEFORESUBMIT;

$dg->add_event("jqGridAddEditAfterSubmit", $beforeSubmit);


Second Method: Database Trigger (SHA2)

CREATE TRIGGER `userInsert`
BEFORE INSERT ON `database`.`users` FOR EACH ROW
BEGIN

  IF LENGTH(NEW.password) != 64 THEN

    SET NEW.password = SHA2(NEW.password,0);

    SET NEW.date_inserted = now();

  END IF;

END


CREATE TRIGGER `userUpdate`
BEFORE UPDATE ON `database`.`users` FOR EACH ROW
BEGIN

  IF LENGTH(NEW.password) != 64 THEN

    SET NEW.password = SHA2(NEW.password,0);

    SET NEW.date_updated = now();

  END IF;

END


Feedback and Knowledge Base