Skip to content

Instantly share code, notes, and snippets.

@maxmcd

maxmcd/main.go Secret

Created August 25, 2019 19:11
Show Gist options
  • Save maxmcd/a32a35c0eebcfb77cd005f9dd8958815 to your computer and use it in GitHub Desktop.
Save maxmcd/a32a35c0eebcfb77cd005f9dd8958815 to your computer and use it in GitHub Desktop.
func validateSFID(input string) bool {
// https://stackoverflow.com/a/29299786/1333724
if len(input) != 18 {
return false
}
parts := []string{input[0:5], input[5:10], input[10:15]}
chars := make([]byte, 3)
for j, word := range parts {
for i, char := range []byte(word) {
// fmt.Println([]byte("AZ")) => [65 90]
if char >= 65 && char <= 90 {
chars[j] += 1 << uint64(i)
}
}
}
for i, c := range chars {
if c <= 25 {
chars[i] = c + 65
} else {
chars[i] = c - 25 + 48
}
}
if string(chars) == input[15:] {
return true
}
return false
}
@SegFaultx64
Copy link

Warning, as of 10/2022 this does not appear to work for all valid Salesforce IDs. It appears to fail on certain ranges of their semi-sequential ids. We got bit by this. Unfortunately I don't have a working version but if I right one up I will link to it here.

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