Initial commit

This commit is contained in:
2021-04-10 07:58:01 +02:00
commit 4bb38a797c
49 changed files with 12483 additions and 0 deletions

21
models/attempt.go Normal file
View File

@@ -0,0 +1,21 @@
package models
import (
"net"
"time"
"github.com/google/uuid"
)
type LoginAttempts []LoginAttempt
type LoginAttempt struct {
ID int `json:"id"`
Date time.Time `json:"date"`
RemoteIP net.IP `json:"remoteIP"`
Username string `json:"username"`
Password string `json:"password"`
SSHClientVersion string `json:"sshClientVersion"`
ConnectionUUID uuid.UUID `json:"connectionUUID"`
Country string `json:"country"`
}

32
models/user.go Normal file
View File

@@ -0,0 +1,32 @@
package models
import (
"fmt"
"golang.org/x/crypto/bcrypt"
)
var ErrInvalidPassword = fmt.Errorf("invalid password")
type User struct {
Username string `json:"username"`
PasswordHash []byte `json:"passwordHash"`
}
func (u *User) SetPassword(password string) error {
newHash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
return fmt.Errorf("error hashing new password: %w", err)
}
u.PasswordHash = newHash
return nil
}
func (u *User) VerifyPassword(password string) error {
err := bcrypt.CompareHashAndPassword([]byte(u.PasswordHash), []byte(password))
if err != nil {
return ErrInvalidPassword
}
return nil
}