Initial commit
This commit is contained in:
		
							
								
								
									
										21
									
								
								models/attempt.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								models/attempt.go
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										32
									
								
								models/user.go
									
									
									
									
									
										Normal 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 | ||||
| } | ||||
		Reference in New Issue
	
	Block a user