~emersion/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH soju] Allow users to change password in client

Details
Message ID
<20200408122000.156038-1-admin@xenrox.net>
DKIM signature
pass
Download raw message
Patch: +31 -0
Added a BouncerServ command for that.
---
 service.go | 23 +++++++++++++++++++++++
 user.go    |  8 ++++++++
 2 files changed, 31 insertions(+)

diff --git a/service.go b/service.go
index fc3773e..4a614d2 100644
--- a/service.go
+++ b/service.go
@@ -7,6 +7,7 @@ import (
	"strings"

	"github.com/google/shlex"
	"golang.org/x/crypto/bcrypt"
	"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()))
	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, fmt.Sprint("updated password"))
	return nil
}
diff --git a/user.go b/user.go
index 018009b..a2e9841 100644
--- a/user.go
+++ b/user.go
@@ -369,3 +369,11 @@ func (u *user) deleteNetwork(id int64) error {

	panic("tried deleting a non-existing network")
}

func (u *user) updatePassword(hashed string) error {
	u.User.Password = hashed
	if err := u.srv.db.UpdatePassword(&u.User); err != nil {
		return err
	}
	return nil
}
-- 
2.26.0
Details
Message ID
<dceRglt0dmUBEmP0tW4GxEiJr7r0blzEZY_PwSdpnO6TYCQWrC2fWbzTe-hcgezQvmeGGiX7xnZ12R3bJWmsEf8s9i2l84jAcD-sfVjwyD8=@emersion.fr>
In-Reply-To
<20200408122000.156038-1-admin@xenrox.net> (view parent)
DKIM signature
pass
Download raw message
Both patches LGTM. Pushed, thanks for your contribution!
Reply to thread Export thread (mbox)