Search code examples
laravelgopassword-hash

How to migrate Laravel project password to Go project?


There is a Laravel project, but has now been refactored into a Go project.

How can a user's password saved using Laravel be verified with Go?

[UPDATE]

I use Hash::make($password) store password in Laravel


Solution

  • I am using following codes solved the question

    import "golang.org/x/crypto/bcrypt"
    
    func Hash(str string) (string, error) {
        hashed, err := bcrypt.GenerateFromPassword([]byte(str), bcrypt.DefaultCost)
        return string(hashed), err
    }
    
    func IsSame(str string, hashed string) bool {
        return bcrypt.CompareHashAndPassword([]byte(hashed), []byte(str)) == nil
    }