Page 2 of 4

Re: USing PHP to refer to Form fields in BS AS BB BE fields

Posted: Fri Feb 12, 2021 4:34 pm
by icoso
kev1n wrote:I'm testing a way to change data before saving (it already works but it's experimental)
To do so, I introduced a new PHP event that is triggered before "BS". Now I'm looking for a good name for it... How about "On Submit" (OS) or is the a more appropriate name?
How about nuPreProcess();

I've been playing with this all night and this morning too with different vars to see what I can change. Anyways I don't understand the array model enough in PHP to do anything with it.

But Im curious why would this need to be done before the BS? Logically I would think that's the place you'd want it to be. (again I don't quite understand a few things in the nudatabase.php and nudata.php and how passing arrays around works). The name doesn't matter. But I wouldn't necessarily want to change whats appearing on the form. For example: an SSN field. I want to encrypt that field when it saves it to the database table, but I don't want it to change on the form screen. I know this is going to introduce a whole new set of issues when trying to retrieve it from the DB, But theoretically, since there is a BeforeSearch function, I should be able to run through the same encryption routine Before the SQL search occurs to encrypt the search field. So the SQL tha gets executed to do the search would use something like this.

$encryptedSSN = doencryptroutine($_POST['cust_SSN'];);
SQL = 'Select * from customers where cust_SSN = $encryptedSSN"

I found that if I did something like below as a test in the BS code. It actually does change the value of that field name but just in the nuhash array. It doesn't save it. It appears to maybe repost the data from the form when it actually saves it. I also get what looks like all the table definitions echoed back on the screen. Not sure why. Since BS was intended to do field eval and stop the processing, Maybe I need to do a return(0); or something like that at the end in the BS code. I found that if I change another field on the form screen it actually does save that field though, so the code below isn't stopping the actual save. Its just not using the data from $_POST['nuHash']['cust_lastname'] to save to the database.

Code: Select all

 
echo $_POST['nuHash']['cust_lastname']." Last1\n";
$_POST['nuHash']['cust_lastname']=$_POST['nuHash']['cust_lastname']."123";
echo $_POST['nuHash']['cust_lastname']." Last2\n";

Re: USing PHP to refer to Form fields in BS AS BB BE fields

Posted: Fri Feb 12, 2021 5:17 pm
by kev1n
Did you see my answer?

Re: USing PHP to refer to Form fields in BS AS BB BE fields

Posted: Fri Feb 12, 2021 6:00 pm
by kev1n
Code updated.

Example:

Code: Select all

// Get the value of the object "not_title"
$title = nuGetNuDataValue($nudata, '', 'not_title');

// Replace the value of the object "not_title" by adding a -test postfix:

nuSetNuDataValue($nudata, '', 'not_title', $title . "-test");
1st parameter is alway $nudata.
2nd parameter: Form Id. If the object is on the main form, pass an empty string

Re: USing PHP to refer to Form fields in BS AS BB BE fields

Posted: Fri Feb 12, 2021 6:16 pm
by icoso
Im assuming you meant to do something like this, right? I updated the nucommon and nudata.php files and logged out and back in.

Code: Select all

    // Get the value of the object "not_title"
    $title = nuGetNuDataValue($nudata, '', 'cust-lastname');

    // Replace the value of the object "not_title" by adding a -test postfix:

$title = $title."123";

    nuSetNuDataValue($nudata, '', 'cust-lastname', $title . "-test");
That worked. I got "Smith123-test" for the last name and it saved it in the DB!

So effectively I could use this to encrypt the SSN in the BS, then let it save it, then unencrypt in the AS so that the field on the form would not update/change to the encrypted data, right?

Or use Javascript to keep the unencrypted field data (SSN) in a variable and then just put it back on the form after saving??? Maybe?

Re: USing PHP to refer to Form fields in BS AS BB BE fields

Posted: Fri Feb 12, 2021 6:31 pm
by kev1n
You would have to use BE to decrypt it and then use nuAddJavascript() to replace the encryped string with the decrypted one.

https://wiki.nubuilder.cloud/ ... Javascript

Re: USing PHP to refer to Form fields in BS AS BB BE fields

Posted: Fri Feb 12, 2021 10:00 pm
by icoso
THis brings us back to this post and how best to actually accomplish encrypting certain fields before saving them or searching for them, in the database and unencrypting them after retrieving them and before displaying them on a form.

https://forums.nubuilder.cloud/viewtopic. ... 2&start=10

I hd responded to this post but have n't seen any replies yet. So Im not so sure how to accomplish this. In some encrypting routines that I wrote for some customers the key that I used varies per user and based upon various data stored in the record and that also can change. Anyways Im wondering if I can include my own encrypting routine is the BS code to change the value of certain fields. IE: include ('myencryptor.php'); to set the field values as previously discussed. and since I wrote my own decryptor routines can I use the in the BB and/or BE code blocks and still use the nuSetNuDataValue($nudata, '', 'cust-lastname', $title . "-test"); function to set that search value?

So for instance, When I go to open a form, the first thing it does is go to the Search screen, where I enter my search data (IE: SSN) and hit search. BUT IT also automatically searches the database and lists the records on that search criteria, which can be stopped using the code you previously show me. So the user has to hit the search button to get any results.

if (nuFormType() == 'browse') {
$('#nuSearchField').on('change keydown paste input propertychange click keyup blur', function() {
nuSetProperty('SEARCH_FIELD', this.value );
})
}

1. So is there a way to execute some PHP code or JavaScript code to encrypt that SSN that I entered BEFORE it performs the search?
2. Is there a way to execute some PHP code or JavaScript code that can be run that when the search button is clicked that the is run against the results before they are displayed? IE: IF the SSN is stored as encrypted data, then searching for 123-44-5566 as-is will never return any results since the SSN is actually store in the DB like 15A6F3F7B8256919D4E3A2394278D6A4B628C1218? So I need a way to modify the search criteria to use a modified search Variable. I hope this makes sense.

Re: USing PHP to refer to Form fields in BS AS BB BE fields

Posted: Sat Feb 13, 2021 8:43 am
by kev1n
icoso wrote: Anyways Im wondering if I can include my own encrypting routine is the BS code to change the value of certain fields. IE: include ('myencryptor.php'); to set the field values as previously discussed. and since I wrote my own decryptor routines can I use the in the BB and/or BE code blocks and still use the nuSetNuDataValue($nudata, '', 'cust-lastname', $title . "-test"); function to set that search value?


Yes, you can.
icoso wrote:
1. So is there a way to execute some PHP code or JavaScript code to encrypt that SSN that I entered BEFORE it performs the search?


Declare a function nuOnSearchAction() in your form's Custom Code. Call a PHP Procedure in int to encrypt the search value and use
nuJavascriptCallback to Refresh the Browse Screen.

You will need the updated nuform.js:
https://github.com/nuBuilder/nuBuilder- ... /nuform.js

Code: Select all

function nuOnSearchAction() {
  nuRunPHPHidden('your_php_procedure_to_encrypt_the_search_value','0);
  result = false;
}

Re: USing PHP to refer to Form fields in BS AS BB BE fields

Posted: Sat Feb 13, 2021 5:33 pm
by miasoft
kev1n wrote:You would have to use BE to decrypt it and then use nuAddJavascript() to replace the encryped string with the decrypted one.

https://wiki.nubuilder.cloud/ ... Javascript
What about it?
MySQL 5.7 FAQ: InnoDB Data-at-Rest Encryption
https://dev.mysql.com/doc/refman/5.7/en ... ption.html
OR
https://www.mysql.com/products/enterprise/tde.html

Re: USing PHP to refer to Form fields in BS AS BB BE fields

Posted: Tue Feb 16, 2021 7:26 pm
by apmuthu
It should be easier to put in a trigger right in the DB itself with some user function in MySQL doing the encrypting job. Decrypting can be PHP.

Re: USing PHP to refer to Form fields in BS AS BB BE fields

Posted: Wed Feb 17, 2021 1:10 am
by icoso
apmuthu wrote:It should be easier to put in a trigger right in the DB itself with some user function in MySQL doing the encrypting job. Decrypting can be PHP.
Can you explain this in detail a little more. not familiar with putting code in the MySql DB itself to do this?