-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwom.go
62 lines (58 loc) · 1.33 KB
/
wom.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package wom
import (
"bytes"
"encoding/json"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
"log"
"net/http"
"unicode"
)
func sendWebhook(webHookURL, message string) {
go func() {
type webhook struct {
Content string `json:"content"`
}
if len(webHookURL) == 0 {
return
}
data := &webhook{
Content: message,
}
dataBytes, err := json.Marshal(data)
if err != nil {
return
}
_, err = http.Post(webHookURL, "application/json", bytes.NewReader(dataBytes))
if err != nil {
return
}
}()
}
func checkGuess(db *daos.Dao, puzzleID, guess string) bool {
records, err := db.FindRecordsByExpr("answers", dbx.HashExp{"puzzle": puzzleID, "content": guess})
if err != nil {
log.Printf("Error checking guess: %s", err)
return false
}
return len(records) == 1
}
func validPassword(password string) bool {
var length, upperCase, lowerCase, number, special bool
if len(password) >= 8 {
length = true
}
for i := range password {
switch {
case unicode.IsUpper(rune(password[i])):
upperCase = true
case unicode.IsLower(rune(password[i])):
lowerCase = true
case unicode.IsNumber(rune(password[i])):
number = true
case unicode.IsPunct(rune(password[i])) || unicode.IsSymbol(rune(password[i])):
special = true
}
}
return length && upperCase && lowerCase && number && special
}