-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasswd.go
More file actions
134 lines (108 loc) · 2.35 KB
/
Copy pathpasswd.go
File metadata and controls
134 lines (108 loc) · 2.35 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//-*- coding: utf-8 -*-
package main
import (
_ "embed"
"html/template"
"log"
"net/http"
)
//go:embed html/setpassord.html
var sethtmlpass string
type SetPwdData struct {
IsPwdexists bool
IsPwddiff bool
IsPwdok bool
}
func setPasswd(w http.ResponseWriter, pwd2 string, pwd3 string) {
oldpwd := getdbpw(db)
pwdexists := oldpwd != " "
pwddiff := pwd2 != pwd3
pwdok := !(pwdexists || pwddiff)
if pwdok {
_ = setdbpw(db, pwd2)
}
t := template.New("Lösenordshantering")
t, _ = t.Parse(sethtmlpass)
data := SetPwdData{
IsPwdexists: pwdexists,
IsPwddiff: pwddiff,
IsPwdok: pwdok,
}
_ = t.Execute(w, data)
}
//go:embed html/chpass.html
var htmlchpass string
type ChPwdData struct {
IsPwdMiss bool
IsPwddiff bool
IsPwdok bool
}
func changePasswd(w http.ResponseWriter, pwd1 string, pwd2 string, pwd3 string) {
oldpwd := getdbpw(db)
pwdmiss := pwd1 != oldpwd
pwddiff := pwd2 != pwd3
pwdok := !(pwdmiss || pwddiff)
if pwdok {
_ = setdbpw(db, pwd2)
}
t := template.New("Lösenordshantering")
t, _ = t.Parse(htmlchpass)
data := ChPwdData{
IsPwdMiss: pwdmiss,
IsPwddiff: pwddiff,
IsPwdok: pwdok,
}
_ = t.Execute(w, data)
}
//go:embed html/delpass.html
var htmldelpass string
type DelPwdData struct {
IsPwdMiss bool
IsPwdok bool
}
func delPasswd(w http.ResponseWriter, pwd1 string) {
oldpwd := getdbpw(db)
pwdmiss := pwd1 != oldpwd
pwdok := !pwdmiss
if pwdok {
_ = setdbpw(db, " ")
}
t := template.New("Lösenordshantering")
t, _ = t.Parse(htmldelpass)
data := DelPwdData{
IsPwdMiss: pwdmiss,
IsPwdok: pwdok,
}
_ = t.Execute(w, data)
}
//go:embed html/passord.html
var htmlpass string
func passwordmgmt(w http.ResponseWriter, req *http.Request) {
//log.Println("passwordmgmt")
err := req.ParseForm()
if err != nil {
log.Fatal(err)
}
//typ := req.FormValue("submit")
//log.Println("typ: ", typ)
action := req.FormValue("action")
//log.Println("action: ", action)
pwd1 := req.FormValue("pwd1")
//log.Println("pwd1: ", pwd1)
pwd2 := req.FormValue("pwd2")
//log.Println("pwd2: ", pwd2)
pwd3 := req.FormValue("pwd3")
//log.Println("pwd3: ", pwd3)
switch action {
case "set":
setPasswd(w, pwd2, pwd3)
case "change":
changePasswd(w, pwd1, pwd2, pwd3)
case "delete":
delPasswd(w, pwd1)
default:
t := template.New("Lösenordshantering")
t, _ = t.Parse(htmlpass)
_ = t.Execute(w, t)
}
}