doumu1951
doumu1951
2018-04-11 01:27

如何将Laravel项目密码迁移到Go项目?

已采纳

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dougaojue8185 dougaojue8185 3年前

    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
    }
    
    点赞 评论 复制链接分享

相关推荐