Skip to content

Instantly share code, notes, and snippets.

Created March 18, 2015 23:36
What would you like to do?
// Users username and password, outputs password + salt
func Password(user string, pass string) string {
var password []byte
var username []byte
// Converts username to bytes
username = []byte("user:" + user + pass)
// Dial up a mongoDB session
session, err := mgo.Dial("")
if err != nil {
return ""
// Opens the "passwords" databases, "salts" collection
c := session.DB("passwords").C("salts")
// Result with store username + password
result := Salting_Struct{}
// Search for the salted username, place in result the salt
c.Find(bson.M{"username": SHA(username)}).One(&result)
// close mongoDB session to free resources
// Converts users input password + generated salt to bytes
password = []byte(pass + result.salt)
return SHA(password)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment