Use config, improve README
This commit is contained in:
parent
2565a6f397
commit
a62901a790
5 changed files with 9 additions and 13 deletions
|
@ -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?
|
||||
* Everything is plain(text) and simple. No databases, encryption, OAuth, or anything fancy. Even the password is plainte- *wait is this a feature?*
|
4
auth.go
4
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
port=7101
|
||||
username=test
|
||||
password=pass
|
||||
export_code=hibiscus
|
2
files.go
2
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
|
||||
|
|
Loading…
Reference in a new issue