diff --git a/README.md b/README.md index 121e841..20b7e1f 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,13 @@ Simple plaintext diary. -This project is *very* opinionated and minimal. It is designed primarily for myself. +This project is *very* opinionated and minimal, and is designed primarily for my usage. +As a result of this, it is also neither secure nor idiot-proof. ## Features: * Each day, you get a txt file. You have until 23:59 of that very day to finalise it. -* At any moment, you can log a single line to the log +* At any moment, you can append a single line to log.txt * You can save named notes to document milestones, big events, or just a nice game you played this month * You can easily export everything in a zip file for backups -* Everything is in plain text. No databases, encryption, OAuth, or anything fancy. Even the password is plain te- wait is this a feature? \ No newline at end of file +* Everything is plain(text) and simple. No databases, encryption, OAuth, or anything fancy. Even the password is plainte- *wait is this a feature?* \ No newline at end of file diff --git a/auth.go b/auth.go index e966d53..e18b002 100644 --- a/auth.go +++ b/auth.go @@ -17,8 +17,8 @@ func basicAuth(next http.Handler) http.Handler { // Calculate SHA-256 hashes for equal length in ConstantTimeCompare usernameHash := sha256.Sum256([]byte(username)) passwordHash := sha256.Sum256([]byte(password)) - expectedUsernameHash := sha256.Sum256([]byte("test")) // TODO: put user & pass outside - expectedPasswordHash := sha256.Sum256([]byte("pass")) + expectedUsernameHash := sha256.Sum256([]byte(Cfg.Username)) + expectedPasswordHash := sha256.Sum256([]byte(Cfg.Password)) usernameMatch := subtle.ConstantTimeCompare(usernameHash[:], expectedUsernameHash[:]) == 1 passwordMatch := subtle.ConstantTimeCompare(passwordHash[:], expectedPasswordHash[:]) == 1 diff --git a/config.go b/config.go index 782426d..54bfaed 100644 --- a/config.go +++ b/config.go @@ -15,15 +15,11 @@ type Config struct { Port int } -func CreateConfig(config Config) { - -} - func LoadConfig() (Config, error) { filename := "config/config.txt" if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) { - CreateConfig(Config{}) + log.Fatal(err) return Config{}, err } diff --git a/config/config.txt b/config/config.txt index ceb3092..3e15fb0 100644 --- a/config/config.txt +++ b/config/config.txt @@ -1,4 +1,3 @@ port=7101 username=test -password=pass -export_code=hibiscus \ No newline at end of file +password=pass \ No newline at end of file diff --git a/files.go b/files.go index d941fbe..e4b3c44 100644 --- a/files.go +++ b/files.go @@ -51,7 +51,7 @@ func PostFile(filename string, w http.ResponseWriter, r *http.Request) { } if _, err := f.Write(body); err != nil { - fmt.Println("Error writing to the file") + fmt.Println("error writing to the file") w.Write([]byte("error writing to file")) w.WriteHeader(http.StatusInternalServerError) return