Allow users to change password in client
Added a BouncerServ command for that.
This commit is contained in:
parent
148bbc8102
commit
20a58b1fa3
23
service.go
23
service.go
@ -7,6 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
"gopkg.in/irc.v3"
|
"gopkg.in/irc.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -118,6 +119,11 @@ func init() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"change-password": {
|
||||||
|
usage: "<new password>",
|
||||||
|
desc: "change your password",
|
||||||
|
handle: handlePasswordChange,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,3 +260,20 @@ func handleServiceNetworkDelete(dc *downstreamConn, params []string) error {
|
|||||||
sendServicePRIVMSG(dc, fmt.Sprintf("deleted network %q", net.GetName()))
|
sendServicePRIVMSG(dc, fmt.Sprintf("deleted network %q", net.GetName()))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handlePasswordChange(dc *downstreamConn, params []string) error {
|
||||||
|
if len(params) != 1 {
|
||||||
|
return fmt.Errorf("expected exactly one argument")
|
||||||
|
}
|
||||||
|
|
||||||
|
hashed, err := bcrypt.GenerateFromPassword([]byte(params[0]), bcrypt.DefaultCost)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to hash password: %v", err)
|
||||||
|
}
|
||||||
|
if err := dc.user.updatePassword(string(hashed)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
sendServicePRIVMSG(dc, "password updated")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
5
user.go
5
user.go
@ -369,3 +369,8 @@ func (u *user) deleteNetwork(id int64) error {
|
|||||||
|
|
||||||
panic("tried deleting a non-existing network")
|
panic("tried deleting a non-existing network")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *user) updatePassword(hashed string) error {
|
||||||
|
u.User.Password = hashed
|
||||||
|
return u.srv.db.UpdatePassword(&u.User)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user