Cleaning up random files a bit

Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
This commit is contained in:
Ethan Wellenreiter 2025-05-01 23:08:09 -04:00
parent f78f26bda5
commit 357382774a
3 changed files with 0 additions and 145 deletions

View File

@ -1,15 +0,0 @@
package auth
type Authenticator interface {
NewUser(username string, password string) error
ChangePassword(username string, oldPassword string, newPassword string) error
ResetPassword(username string, newPassword string) error // need to enable some sort of authorization stuff
DeleteUser(username string, password string) error
CreateSessionTokens() (token string, regentoken string, err error)
RegenSessionTokens(regenToken string) (token string, regentoken string, err error)
ValidateToken(token string) error
EndSession() error
// need to figure out the role stuff
}

View File

@ -1,130 +0,0 @@
package auth
import (
"git.ewellenr.ca/receipt_indexer/backend/internal/lcrypto"
"git.ewellenr.ca/receipt_indexer/backend/internal/storage"
)
type LocalAuth struct {
sessStore storage.SessionStore
userStore storage.UserStore
crypographer lcrypto.Hasher
sessionKeyLength uint
}
func generateSessionKey(length uint) (string, error) {
key, err := lcrypto.GenerateRandomBytes(length)
return string(key), err
}
func (la *LocalAuth) NewUser(username string, password string) (err error) {
// check for existing user
}
func (la *LocalAuth) CreateSessionTokens() (token string, regentoken string, err error) {
token, err = generateSessionKey(la.sessionKeyLength)
if err != nil {
return "", "", err
}
err = la.sessStore.AddSession(token)
return "", "", err
}
// // argon2 parameter struct
// type Argon2params struct {
// Memory uint32
// Iterations uint32
// Parallelism uint8
// SaltLength uint32
// KeyLength uint32
// }
// var DefaultArgon2Params = &Argon2params{
// Memory: 64 * 1024,
// Iterations: 1,
// Parallelism: uint8(runtime.NumCPU()),
// SaltLength: 16,
// KeyLength: 32,
// }
// func (p *Argon2params) GeneratePassEncoding(password string) (encoding string, err error) {
// salt, err := generateRandomBytes(uint(p.SaltLength))
// if err != nil {
// return "", err
// }
// hash := argon2.IDKey([]byte(password), salt, p.Iterations, p.Memory, p.Parallelism, p.KeyLength)
// // Base64 encode the salt and hashed password.
// b64Salt := base64.RawStdEncoding.EncodeToString(salt)
// b64Hash := base64.RawStdEncoding.EncodeToString(hash)
// // Return a string using the standard encoded hash representation.
// encoding = fmt.Sprintf("$argon2id$v=%d$m=%d,t=%d,p=%d$%s$%s", argon2.Version, p.Memory, p.Iterations, p.Parallelism, b64Salt, b64Hash)
// return encoding, nil
// }
// func CheckPasswordAgainstEncoding(password string, encodedHash string) (match bool, err error) {
// p, salt, hash, err := decodeHash(encodedHash)
// if err != nil {
// return false, err
// }
// // Derive the key from the other password using the same parameters.
// otherHash := argon2.IDKey([]byte(password), salt, p.Iterations, p.Memory, p.Parallelism, p.KeyLength)
// // Check that the contents of the hashed passwords are identical. Note
// // that we are using the subtle.ConstantTimeCompare() function for this
// // to help prevent timing attacks.
// if subtle.ConstantTimeCompare(hash, otherHash) == 1 {
// return true, nil
// }
// return false, nil
// }
// // PRIVATE STUFF
// // error statements
// var ErrInvalidHash = errors.New("the encoded hash is not in the correct format")
// var ErrIncompatibleVersion = errors.New("incompatible version of argon2")
// func decodeHash(encodedHash string) (p *Argon2params, salt []byte, hash []byte, err error) {
// vals := strings.Split(encodedHash, "$")
// if len(vals) != 6 {
// return nil, nil, nil, ErrInvalidHash
// }
// var version int
// _, err = fmt.Sscanf(vals[2], "v=%d", &version)
// if err != nil {
// return nil, nil, nil, err
// }
// if version != argon2.Version {
// return nil, nil, nil, ErrIncompatibleVersion
// }
// p = &Argon2params{}
// _, err = fmt.Sscanf(vals[3], "m=%d,t=%d,p=%d", &p.Memory, &p.Iterations, &p.Parallelism)
// if err != nil {
// return nil, nil, nil, err
// }
// salt, err = base64.RawStdEncoding.Strict().DecodeString(vals[4])
// if err != nil {
// return nil, nil, nil, err
// }
// p.SaltLength = uint32(len(salt))
// hash, err = base64.RawStdEncoding.Strict().DecodeString(vals[5])
// if err != nil {
// return nil, nil, nil, err
// }
// p.KeyLength = uint32(len(hash))
// return p, salt, hash, nil
// }