Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Encrypting a Field that is used for searching

Questions related to customising nuBuilder Forte with JavaScript or PHP.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Encrypting a Field that is used for searching

Unread post by kev1n »

The code that is assigned to the $js variable is not the same as mine.
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Re: Encrypting a Field that is used for searching

Unread post by icoso »

It is the same:

HEre is what you put:

Code: Select all

$e = encryptString("#nuSearchField#");
$js =
"
  window.originalSearchString = '#nuSearchField#';
  nuForm(nuGetProperty('form_id'),'' , '', '$e', '1');

";
nuJavascriptCallback($js);
Here is what I put. As I mentioned. I could not get the line "window.originalSearchString = '#nuSearchField#';" to change the field, so I tried using the DOM Element to do it to. Also since it would not work I tried moving the winwow.nuSearchField after the nuform command. That didn't work either. The only thing I added , I had remarked out using the //

Code: Select all

$e = encryptSSN("#nuSearchField#");
$js =
"
  window.nuSearchField = '#nuSearchField#';
  nuForm(nuGetProperty('form_id'),'' , '', '$e', '1');


";
nuJavascriptCallback($js);
I cut and pasted your exact code ONLY changing the name of the function that I called from encryptString to encryptSSN. It still does the same thing. It retrieves the data but it changes my search string to the encrypted string How could that make a difference if my function is named encryptSSN?
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Encrypting a Field that is used for searching

Unread post by kev1n »

Could you try my code 1:1 ?

E.g. this is different from my code.

Code: Select all

if (nuFormType() == 'browse') {
   $('#nuSearchField').on('change keydown paste input propertychange click keyup blur', function() {
       nuSetProperty('SEARCH_FIELD', this.value );   
  })
  nuAddActionButton('encrpytSearch', 'Search SSN Encrypted','searchSSN();');
}
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Re: Encrypting a Field that is used for searching

Unread post by icoso »

Yes, I can try it, but you had provided that code previously as a way to keep the search form from automatically running the search on the first search field and displaying all the records. I don't want to lose that ability. I don't want the search to automatically start searching unless I click the search button.

Here is your post where you said: "I use this "trick" to start with a blank Search Form:"

https://forums.nubuilder.cloud/viewtopic. ... 819#p23053
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Encrypting a Field that is used for searching

Unread post by kev1n »

Does it work with this Custom Code?

Code: Select all

function nuOnSearchAction() {

    window.originalSearchString = undefined;
    return true;

}

function searchSSN() {

    // Store the Search String in a Hash Cookie nuSearchField
    nuSetProperty('nuSearchField', $('#nuSearchField').val());

    // Run the PHP Procedure searchSSN
    nuRunPHPHidden("searchSSN", 0);

}


if (nuFormType() == 'browse') {

    // Add an additional button "Search SSN" next to the other action buttons
    if (window.originalSearchString !== undefined) {
        $('#nuSearchField').val(window.originalSearchString);
    }

    $('#nuSearchField').on('change keydown paste input propertychange click keyup blur', function() {
        nuSetProperty('SEARCH_FIELD', this.value);
    })
    
    nuAddActionButton('encrpytSearch', 'Search SSN Encrypted', 'searchSSN();');
  
}
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Re: Encrypting a Field that is used for searching

Unread post by icoso »

Yes, that worked. However, I actually see this "#nuOrgSearchField#" flash into the search field before it changes again to the original search text that I typed. Why?
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Re: Encrypting a Field that is used for searching

Unread post by icoso »

kev1n wrote:
icoso wrote: Also, In the list of records that were retrieved, IS there any way to change what is displayed there for the SSNs? It is currently displaying the encrypted string and not the SSN from the database.
How can I display the unencrypted SSN field there? What functions and/or code section can I use to unencrypt the SSN when it's displayed?
I'll have to think about what the best option is there.
Kev1n, Have you thought about this? Is there a way using this standard search form and the Search SSN button I created, list the decrypted data after running through the unencryption function. The process is that I take the data that was entered into the search field, run it through my encryption function (using a Search SSN button not he standard search button) to encrypt the search field so that the standard search from will search the database using the encrypted SSN. However what it lists is the encrypted SSN from the database. Is there some way to call my decryption procedure or include it from a file that would take the cust_prissn field and decrypt it, before its displayed on the form.

Im assuming that your php routine to list the records that it finds could include some type of hook to run a field that is on the Browse page through a php function to modify the data before its displayed. I think this would work, kind of like what I did for the Reports in this post: https://forums.nubuilder.cloud/viewtopic.php?f=20&t=10866

When looking at the Custom code for my form, there is a BB code (Before Browse). How is that used in listing the records that were searched? OR on the Browse page, where you enter the SQL statement to use, is there something in there that we could include a hook to a php procedure or file after the SQL is run to modify the results before they're listed?

How does the search form work? Does it create a temporary table or does it retrieve the results in a memory space? Like I found out I had to do in that topic above regarding the reports.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Encrypting a Field that is used for searching

Unread post by kev1n »

Until I come up with a good solution to modify the rows before displaying them, you could patch nuform.php to include your decryption procedure:

Afer this row

Code: Select all

	$f->browse_rows			= nuObjKey($B,0,0);
https://github.com/nuBuilder/nuBuilder- ... m.php#L373

Add your code

Code: Select all

if ($f->form_id == 'your_form_id_here') {
	if ($f->browse_rows != 0 && nuObjKey($f->browse_rows,0,0) != 0) {			
	for($d = 0 ; $d < count($f->browse_rows[0]) ; $d++){
			// nuDebug($f->browse_rows[$d][1]);
                        // E.g. manipulate the 2nd column of the first row by adding a xx
			$f->browse_rows[$d][1] = $f->browse_rows[$d][1]."xx";				
	}
	}
}
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Encrypting a Field that is used for searching

Unread post by kev1n »

Were you able to test my suggestion?
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Encrypting a Field that is used for searching

Unread post by kev1n »

A possibility has been added to pre-process rows:

https://forums.nubuilder.cloud/viewtopic.php?f=31&t=10939
Post Reply