-
Notifications
You must be signed in to change notification settings - Fork 2
add salt function #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| } | ||
|
|
||
| // RandomSalt generates a random ten-digit number as a string | ||
| // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to register your function as well here:
qlbridge/expr/builtins/builtins.go
Line 127 in 85f4541
| expr.FuncAdd("hash.sha512", &HashSha512{}) |
something like:
expr.FuncAdd("random.salt", &RandomSalt{})
| } | ||
| func randomSaltEval(ctx expr.EvalContext, args []value.Value) (value.Value, bool) { | ||
| // Generate a random number between 1000000000 and 9999999999 | ||
| randomNum := rand.Int63n(9000000000) + 1000000000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to use the crypto rand here? I think we need to fix the imports for the file too...
import "crypto/rand"
...
salt := make([]byte, 10)
if ib, err := rand.Read(salt); err != nil && ib != len(salt) {
return value.EmptyStringValue, false
}
return value.NewStringValue(base64.URLEncoding.EncodeToString(salt)), true| } | ||
| return value.NewStringValue(string(by)), true | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im going to talk this one over with the team tomorrow. If the goal here is to have this generate a random salt, that is only set once and never changed. We may need to write this as one of our internal built-ins, so it has context from the entire entity. Otherwise each time the profile is evaluated it's salt will change, which will change it's hashed email address.
Add a salt function to ql built in expr.