Compare commits

..

No commits in common. "244c701519f45d29f7934d0e8d63dda91282a37c" and "4718dba626cbc1a1453df44635c77a938cacff30" have entirely different histories.

4 changed files with 1 additions and 117 deletions

View File

@ -1,38 +0,0 @@
package models
import (
"errors"
"time"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
)
type User struct {
ID uint `gorm:"primarykey" json:"id"`
Username string `gorm:"unique" json:"username"`
Password string `json:"-"`
Email string `json:"email"`
Phone string `json:"phone"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (u *User) BeforeCreate(tx *gorm.DB) error {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(u.Password), bcrypt.DefaultCost)
if err != nil {
return err
}
u.Password = string(hashedPassword)
return nil
}
func (u *User) ComparePassword(password string) error {
//直接比较密码不用bcrypt
if u.Password == password {
return nil
} else {
return errors.New("error password")
// bcrypt.CompareHashAndPassword([]byte(u.Password), []byte(password))
}
}

View File

@ -1,38 +0,0 @@
package models
import (
"errors"
"time"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
)
type User struct {
ID uint `gorm:"primarykey" json:"id"`
Username string `gorm:"unique" json:"username"`
Password string `json:"-"`
Email string `json:"email"`
Phone string `json:"phone"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (u *User) BeforeCreate(tx *gorm.DB) error {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(u.Password), bcrypt.DefaultCost)
if err != nil {
return err
}
u.Password = string(hashedPassword)
return nil
}
func (u *User) ComparePassword(password string) error {
//直接比较密码不用bcrypt
if u.Password == password {
return nil
} else {
return errors.New("error password")
// bcrypt.CompareHashAndPassword([]byte(u.Password), []byte(password))
}
}

View File

@ -1,38 +0,0 @@
package models
import (
"errors"
"time"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
)
type User struct {
ID uint `gorm:"primarykey" json:"id"`
Username string `gorm:"unique" json:"username"`
Password string `json:"-"`
Email string `json:"email"`
Phone string `json:"phone"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (u *User) BeforeCreate(tx *gorm.DB) error {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(u.Password), bcrypt.DefaultCost)
if err != nil {
return err
}
u.Password = string(hashedPassword)
return nil
}
func (u *User) ComparePassword(password string) error {
//直接比较密码不用bcrypt
if u.Password == password {
return nil
} else {
return errors.New("error password")
// bcrypt.CompareHashAndPassword([]byte(u.Password), []byte(password))
}
}

View File

@ -1,7 +1,6 @@
package models
import (
"errors"
"time"
"golang.org/x/crypto/bcrypt"
@ -32,7 +31,6 @@ func (u *User) ComparePassword(password string) error {
if u.Password == password {
return nil
} else {
return errors.New("error password")
// bcrypt.CompareHashAndPassword([]byte(u.Password), []byte(password))
return bcrypt.CompareHashAndPassword([]byte(u.Password), []byte(password))
}
}