This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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("127.0.0.1:27017/") | |
if err != nil { | |
fmt.Println(err) | |
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 | |
session.Close() | |
// 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