Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
dspvs
Contributor
Contributor

Randomised hash-function

Hello all,

I am currently working on a project where I need to hash a certain field with values of usernames. The project is only for internal use. Thus I use the hash128()-function in the script.

Although the usernames need to be hashed, it is also reuqiered to access the unhashed values from time to time. This will be done manually by reloading the app once without the hash-function and then hash the field again.

The challenge is that if I hash the usernames, then unhash them and hash them again, the "second hashed values" are excactly the same as the ones before.

This means for example the username "Mike" will be "XYZ" when hashed the first time, unhashed it will be "Mike" again and then after reloading it with hash(usernames) it is "XYZ" again.

Is there any way to randomise the hash function every time when reloading the app?

I tried hash128(username, rand()) but that doesn't work properly. It leads to random values for every single time "Mike" is part of the data.

Thanks in advance!

Labels (1)
1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think you are on the right track with rand(), you just need to use something that is unique per script run but constant for the duration of the run. How about

LET vNow = Num(Now());

LOAD
hash128(username, $(vNow)) as Hashed
...

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

View solution in original post

3 Replies
david990
Contributor
Contributor

By design, a hash function can not be reversed.

you could use something that change character with special character and mix it in a reversible way

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think you are on the right track with rand(), you just need to use something that is unique per script run but constant for the duration of the run. How about

LET vNow = Num(Now());

LOAD
hash128(username, $(vNow)) as Hashed
...

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

dspvs
Contributor
Contributor
Author

@rwunderlich Thanks a lot - the solution with a separate variable works fine!