Its pretty straightforward. The passes don't match. I can't find why.
The hashing function
package utils
var hasher = md5.New()
func GetMD5Hash(text string) string {
fmt.Println(">> ", text, "<<")
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
`
I make 1st restful call to create a user (register) calls this method.
func CreateUser(id bson.ObjectId, email string, password string) bool {
var user User
user.ID = id
user.Email = email
user.Password = utils.GetMD5Hash(password)
// fmt.Println("In Create User:", password, user.Password)
err := userCollection.Insert(&user)
if err != nil {
log.Println("Error while CreateUser")
return false
}
return true
}
Now I make 2nd restful call to authenticate (login)
The Authenticate User Method
func AuthenticateUser(email string, password string) bool {
user := GetUserByEmail(email)
var u User
u.Password = utils.GetMD5Hash(password)
fmt.Println("In Authenticate:", password, u.Password)
fmt.Println(u.Password, user.Password)
if u.Password == user.Password {
return true
}
return false
}
PASSWORDS DONT MATCH.
Results:
>> pass <<
In Authenticate: pass 1a1dc91c907325c69271ddf0c944bc72
1a1dc91c907325c69271ddf0c944bc72 1a1dc91c907325c69271ddf0c944bc72
>> pass <<
{ObjectIdHex("5ae3746e1b2a612417149bca") []}
>> pass <<
In Authenticate: pass dbe4a8e3a3b93ed3101bace4bc19fc70
dbe4a8e3a3b93ed3101bace4bc19fc70 078bbb4bf0f7117fb131ec45f15b5b87
>> pass <<
{ObjectIdHex("5ae374a31b2a612417149bcb") []}
>> pass <<
In Authenticate: pass c4e6ffe7c63bb65e68521293416c96a2
c4e6ffe7c63bb65e68521293416c96a2 1bdfd5f0b03c0d80557384602303c690
>> pass <<
In Authenticate: pass c6d90629ad5c6b8edbe479340d5bed6b
c6d90629ad5c6b8edbe479340d5bed6b 1bdfd5f0b03c0d80557384602303c690
>> pass <<
In Authenticate: pass 5b54f4793a13c985b4f4275980542496
5b54f4793a13c985b4f4275980542496 1bdfd5f0b03c0d80557384602303c690
If it is not clear, I am literally making the same request repeatedly and every time results in a new MD5Hash. Also, both the register and login process uses the same UI, same text boxes different buttons.
Insights. Please.