Changeset 252 in code for trunk


Ignore:
Timestamp:
Apr 10, 2020, 8:16:25 AM (5 years ago)
Author:
admin
Message:

Allow users to change password in client

Added a BouncerServ command for that.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/service.go

    r224 r252  
    88
    99        "github.com/google/shlex"
     10        "golang.org/x/crypto/bcrypt"
    1011        "gopkg.in/irc.v3"
    1112)
     
    119120                        },
    120121                },
     122                "change-password": {
     123                        usage:  "<new password>",
     124                        desc:   "change your password",
     125                        handle: handlePasswordChange,
     126                },
    121127        }
    122128}
     
    255261        return nil
    256262}
     263
     264func handlePasswordChange(dc *downstreamConn, params []string) error {
     265        if len(params) != 1 {
     266                return fmt.Errorf("expected exactly one argument")
     267        }
     268
     269        hashed, err := bcrypt.GenerateFromPassword([]byte(params[0]), bcrypt.DefaultCost)
     270        if err != nil {
     271                return fmt.Errorf("failed to hash password: %v", err)
     272        }
     273        if err := dc.user.updatePassword(string(hashed)); err != nil {
     274                return err
     275        }
     276
     277        sendServicePRIVMSG(dc, "password updated")
     278        return nil
     279}
  • trunk/user.go

    r241 r252  
    370370        panic("tried deleting a non-existing network")
    371371}
     372
     373func (u *user) updatePassword(hashed string) error {
     374        u.User.Password = hashed
     375        return u.srv.db.UpdatePassword(&u.User)
     376}
Note: See TracChangeset for help on using the changeset viewer.