mirror of https://github.com/gogs/gogs.git
refactor(db): rename `User.Passwd` to `User.Password` (#7196)
parent
c502dc6ed8
commit
7cbd84d5b3
|
@ -154,7 +154,7 @@ func runCreateUser(c *cli.Context) error {
|
|||
if err := db.CreateUser(&db.User{
|
||||
Name: c.String("name"),
|
||||
Email: c.String("email"),
|
||||
Passwd: c.String("password"),
|
||||
Password: c.String("password"),
|
||||
IsActive: true,
|
||||
IsAdmin: c.Bool("admin"),
|
||||
}); err != nil {
|
||||
|
|
|
@ -185,7 +185,7 @@ func authenticatedUser(ctx *macaron.Context, sess session.Store) (_ *db.User, is
|
|||
u := &db.User{
|
||||
Name: webAuthUser,
|
||||
Email: gouuid.NewV4().String() + "@localhost",
|
||||
Passwd: webAuthUser,
|
||||
Password: webAuthUser,
|
||||
IsActive: true,
|
||||
}
|
||||
if err = db.CreateUser(u); err != nil {
|
||||
|
|
|
@ -42,7 +42,7 @@ func (this mailerUser) GenerateEmailActivateCode(email string) string {
|
|||
this.user.ID,
|
||||
email,
|
||||
this.user.Name,
|
||||
this.user.Passwd,
|
||||
this.user.Password,
|
||||
this.user.Rands,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -168,15 +168,15 @@ func (u *User) NewGitSig() *git.Signature {
|
|||
|
||||
// EncodePassword encodes password to safe format.
|
||||
func (u *User) EncodePassword() {
|
||||
newPasswd := pbkdf2.Key([]byte(u.Passwd), []byte(u.Salt), 10000, 50, sha256.New)
|
||||
u.Passwd = fmt.Sprintf("%x", newPasswd)
|
||||
newPasswd := pbkdf2.Key([]byte(u.Password), []byte(u.Salt), 10000, 50, sha256.New)
|
||||
u.Password = fmt.Sprintf("%x", newPasswd)
|
||||
}
|
||||
|
||||
// ValidatePassword checks if given password matches the one belongs to the user.
|
||||
func (u *User) ValidatePassword(passwd string) bool {
|
||||
newUser := &User{Passwd: passwd, Salt: u.Salt}
|
||||
newUser := &User{Password: passwd, Salt: u.Salt}
|
||||
newUser.EncodePassword()
|
||||
return subtle.ConstantTimeCompare([]byte(u.Passwd), []byte(newUser.Passwd)) == 1
|
||||
return subtle.ConstantTimeCompare([]byte(u.Password), []byte(newUser.Password)) == 1
|
||||
}
|
||||
|
||||
// UploadAvatar saves custom avatar for user.
|
||||
|
@ -499,7 +499,7 @@ func VerifyUserActiveCode(code string) (user *User) {
|
|||
if user = parseUserFromCode(code); user != nil {
|
||||
// time limit code
|
||||
prefix := code[:tool.TIME_LIMIT_CODE_LENGTH]
|
||||
data := com.ToStr(user.ID) + user.Email + user.LowerName + user.Passwd + user.Rands
|
||||
data := com.ToStr(user.ID) + user.Email + user.LowerName + user.Password + user.Rands
|
||||
|
||||
if tool.VerifyTimeLimitCode(data, minutes, prefix) {
|
||||
return user
|
||||
|
@ -515,7 +515,7 @@ func VerifyActiveEmailCode(code, email string) *EmailAddress {
|
|||
if user := parseUserFromCode(code); user != nil {
|
||||
// time limit code
|
||||
prefix := code[:tool.TIME_LIMIT_CODE_LENGTH]
|
||||
data := com.ToStr(user.ID) + email + user.LowerName + user.Passwd + user.Rands
|
||||
data := com.ToStr(user.ID) + email + user.LowerName + user.Password + user.Rands
|
||||
|
||||
if tool.VerifyTimeLimitCode(data, minutes, prefix) {
|
||||
emailAddress := &EmailAddress{Email: email}
|
||||
|
|
|
@ -230,7 +230,7 @@ func (db *users) Create(ctx context.Context, username, email string, opts Create
|
|||
Name: username,
|
||||
FullName: opts.FullName,
|
||||
Email: email,
|
||||
Passwd: opts.Password,
|
||||
Password: opts.Password,
|
||||
LoginSource: opts.LoginSource,
|
||||
LoginName: opts.LoginName,
|
||||
Location: opts.Location,
|
||||
|
@ -355,7 +355,7 @@ type User struct {
|
|||
FullName string
|
||||
// Email is the primary email address (to be used for communication)
|
||||
Email string `xorm:"NOT NULL" gorm:"not null"`
|
||||
Passwd string `xorm:"NOT NULL" gorm:"not null"`
|
||||
Password string `xorm:"passwd NOT NULL" gorm:"column:passwd;not null"`
|
||||
LoginSource int64 `xorm:"NOT NULL DEFAULT 0" gorm:"not null;default:0"`
|
||||
LoginName string
|
||||
Type UserType
|
||||
|
|
|
@ -79,7 +79,7 @@ func NewUserPost(c *context.Context, f form.AdminCrateUser) {
|
|||
u := &db.User{
|
||||
Name: f.UserName,
|
||||
Email: f.Email,
|
||||
Passwd: f.Password,
|
||||
Password: f.Password,
|
||||
IsActive: true,
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ func EditUserPost(c *context.Context, f form.AdminEditUser) {
|
|||
}
|
||||
|
||||
if len(f.Password) > 0 {
|
||||
u.Passwd = f.Password
|
||||
u.Password = f.Password
|
||||
var err error
|
||||
if u.Salt, err = db.GetUserSalt(); err != nil {
|
||||
c.Error(err, "get user salt")
|
||||
|
|
|
@ -41,7 +41,7 @@ func CreateUser(c *context.APIContext, form api.CreateUserOption) {
|
|||
Name: form.Username,
|
||||
FullName: form.FullName,
|
||||
Email: form.Email,
|
||||
Passwd: form.Password,
|
||||
Password: form.Password,
|
||||
IsActive: true,
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ func EditUser(c *context.APIContext, form api.EditUserOption) {
|
|||
}
|
||||
|
||||
if len(form.Password) > 0 {
|
||||
u.Passwd = form.Password
|
||||
u.Password = form.Password
|
||||
var err error
|
||||
if u.Salt, err = db.GetUserSalt(); err != nil {
|
||||
c.Error(err, "get user salt")
|
||||
|
|
|
@ -390,7 +390,7 @@ func InstallPost(c *context.Context, f form.Install) {
|
|||
u := &db.User{
|
||||
Name: f.AdminName,
|
||||
Email: f.AdminEmail,
|
||||
Passwd: f.AdminPasswd,
|
||||
Password: f.AdminPasswd,
|
||||
IsAdmin: true,
|
||||
IsActive: true,
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ func AutoLogin(c *context.Context) (bool, error) {
|
|||
return false, nil
|
||||
}
|
||||
|
||||
if val, ok := c.GetSuperSecureCookie(u.Rands+u.Passwd, conf.Security.CookieRememberName); !ok || val != u.Name {
|
||||
if val, ok := c.GetSuperSecureCookie(u.Rands+u.Password, conf.Security.CookieRememberName); !ok || val != u.Name {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ func afterLogin(c *context.Context, u *db.User, remember bool) {
|
|||
if remember {
|
||||
days := 86400 * conf.Security.LoginRememberDays
|
||||
c.SetCookie(conf.Security.CookieUsername, u.Name, days, conf.Server.Subpath, "", conf.Security.CookieSecure, true)
|
||||
c.SetSuperSecureCookie(u.Rands+u.Passwd, conf.Security.CookieRememberName, u.Name, days, conf.Server.Subpath, "", conf.Security.CookieSecure, true)
|
||||
c.SetSuperSecureCookie(u.Rands+u.Password, conf.Security.CookieRememberName, u.Name, days, conf.Server.Subpath, "", conf.Security.CookieSecure, true)
|
||||
}
|
||||
|
||||
_ = c.Session.Set("uid", u.ID)
|
||||
|
@ -334,7 +334,7 @@ func SignUpPost(c *context.Context, cpt *captcha.Captcha, f form.Register) {
|
|||
u := &db.User{
|
||||
Name: f.UserName,
|
||||
Email: f.Email,
|
||||
Passwd: f.Password,
|
||||
Password: f.Password,
|
||||
IsActive: !conf.Auth.RequireEmailConfirmation,
|
||||
}
|
||||
if err := db.CreateUser(u); err != nil {
|
||||
|
@ -544,7 +544,7 @@ func ResetPasswdPost(c *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
u.Passwd = passwd
|
||||
u.Password = passwd
|
||||
var err error
|
||||
if u.Rands, err = db.GetUserSalt(); err != nil {
|
||||
c.Error(err, "get user salt")
|
||||
|
|
|
@ -202,7 +202,7 @@ func SettingsPasswordPost(c *context.Context, f form.ChangePassword) {
|
|||
} else if f.Password != f.Retype {
|
||||
c.Flash.Error(c.Tr("form.password_not_match"))
|
||||
} else {
|
||||
c.User.Passwd = f.Password
|
||||
c.User.Password = f.Password
|
||||
var err error
|
||||
if c.User.Salt, err = db.GetUserSalt(); err != nil {
|
||||
c.Errorf(err, "get user salt")
|
||||
|
|
Loading…
Reference in New Issue