Skip to content

Conversation

@tonytusharjr
Copy link

Add a salt function to ql built in expr.

}

// RandomSalt generates a random ten-digit number as a string
//
Copy link
Contributor

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:

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
Copy link
Contributor

@epsniff epsniff May 16, 2025

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
}

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants