htpasswd: refactor and add Passwd methods #3
Reference in New Issue
Block a user
Delete Branch "pr-karasz-refactor"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Signed-off-by: Nagy Károly Gábriel k@jpi.io
please see comments
@@ -104,15 +86,25 @@ func CreateUser(file, user, passwd string, algo HashAlgorithm) error {if err != nil {return err}newpp, err := pp.CreateUser(user, passwd, algo)as it's a map, newpp and pp are actually the same map and both contain the new user.
if we really want a new map this should be via a
newpp, err := pp.Clone().AddUser(...)@@ -173,0 +188,4 @@}// Byte will return the Passwd as a byte slicefunc (pp Passwds) Byte() []byte {standard is
Bytes()as the returned value contains many.WriteTo()is also a nice interface@@ -188,10 +243,55 @@ func verifyPass(pass, hash string, alg HashAlgorithm) error {return fmt.Errorf("unsupported hash algorithm %v", alg)}func identifyHash(h string) (HashAlgorithm, error) {wouldn't it be better to return a split?
(algo, hash, bool)?@@ -192,3 +271,4 @@return apr1_crypt.New().Verify(hashedPassword, []byte(password))}func hashBcrypt(passwd string) (string, error) {method of the algo sharing an interface?
@@ -269,6 +399,16 @@ func verifySHA256(password, hashedPassword string) error {return nil}func hashSha512(passwd string) (string, error) {begging for the Hasher interface
@@ -107,2 +98,3 @@func (pp Passwds) CreateUser(user, passwd string, algo HashAlgorithm) (Passwds, error) {if _, exists := pp[user]; exists {return fmt.Errorf("user %s already exists", user)return nil, fmt.Errorf("user %s already exists", user)we may want errors that can be tested without parsing the content
Not sure what you mean
usage or wrapping predefined errors so one can use errors.Is() and similar
56008698b2to5f5cbeab4f