I have a list of integers (emplyoee ID's) They are 8 digits long (although almost all start 00, but they are effectively 8 digits long)
For each employee I need to generate a key that is:
- 5 chars including [A-Z][a-z][0-9]
- Must include 1 of [A-Z]
- Must include 1 of [0-9]
- Generated key must be unique
- If I know an employees ID I should not be able to determine their key
I need to produce an algorithm that will generate the keys but I want to avoid having to record keys against employees if possible. The more I think about it the more problems I encounter.
If I can avoid it I don't want to generate all the keys and store them somewhere - I would rather they are calculated on the fly
I am allowed to hide a secret in my system which I could use to make sure the keys are non deterministic unless you know the secret.
I thought of using standard hash algroythms (with salt) but the limits of the target space and limits of including 1 A-Z and 1 0-9 seem to prevent this.
One way I think I might use to solve the problem:
1. Build a deteremnistic function that maps integers starting from 1 [1, 2, 3, ...] to every possible result value
2. Map integers [1, 2, ...] to random other integers in the desired range [324, 43565, ...] in a way that preserves uniqueness (based on a secret salt which if changed would result in a different order).
This would guarantee uniqueness but step 1 is tricky. The result set is discontinuous, some values may be missing a capital letter and others will miss a number.
I could get round this by starting every code with A1 which technically would work but reduced the result space from a 5 chars to 3 chars.
Can anyone suggest something simple that will work and avoid me having to keep a record of all generated results for unique checking?
Aucun commentaire:
Enregistrer un commentaire