Skip to content

Instantly share code, notes, and snippets.

Created March 18, 2015 23:36
What would you like to do?
// Generates a salt for the given user
func GenerateSalt(user string, pass string) string {
var password []byte
var username []byte
username = []byte("user:" + user + pass)
// Dial up a mongoDB session
session, _ := mgo.Dial("")
// Opens the "passwords" databases, "salts" collection
c := session.DB("passwords").C("salts")
// Result with store username + password
result := Salting_Struct{}
// Generate random number, then use SHA-2 algorithm for salt
// Take only the first 12 digits for salt
result.Salt := SHA(string(rand.Intn(10000000)))[12:]
// Search for the salted username, place in result the salt
// close mongoDB session to free resources
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment