2016-11-13 19:50:44 +07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/satori/go.uuid"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
|
|
"unicode/utf8"
|
|
|
|
)
|
|
|
|
|
2016-11-23 22:11:31 +07:00
|
|
|
func getValidUsername(u string) (uuid.UUID, error) {
|
2016-11-13 19:50:44 +07:00
|
|
|
uname, err := uuid.FromString(u)
|
|
|
|
if err != nil {
|
|
|
|
return uuid.UUID{}, err
|
|
|
|
}
|
|
|
|
return uname, nil
|
|
|
|
}
|
|
|
|
|
2016-11-23 22:11:31 +07:00
|
|
|
func validKey(k string) bool {
|
|
|
|
kn := sanitizeString(k)
|
2016-11-13 19:50:44 +07:00
|
|
|
if utf8.RuneCountInString(k) == 40 && utf8.RuneCountInString(kn) == 40 {
|
|
|
|
// Correct length and all chars valid
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-11-23 22:11:31 +07:00
|
|
|
func validSubdomain(s string) bool {
|
2016-11-13 19:50:44 +07:00
|
|
|
_, err := uuid.FromString(s)
|
|
|
|
if err == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-11-23 22:11:31 +07:00
|
|
|
func validTXT(s string) bool {
|
|
|
|
sn := sanitizeString(s)
|
2016-11-13 19:50:44 +07:00
|
|
|
if utf8.RuneCountInString(s) == 43 && utf8.RuneCountInString(sn) == 43 {
|
|
|
|
// 43 chars is the current LE auth key size, but not limited / defined by ACME
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-11-23 22:11:31 +07:00
|
|
|
func correctPassword(pw string, hash string) bool {
|
2016-11-13 19:50:44 +07:00
|
|
|
if err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(pw)); err == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|