photoprism/pkg/rnd/session.go
Michael Mayer f5a8c5a45d Auth: Session and ACL enhancements #98 #1746
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-09-28 09:01:17 +02:00

28 lines
381 B
Go

package rnd
import (
"crypto/rand"
"fmt"
"log"
)
// SessionID returns a new session id.
func SessionID() string {
b := make([]byte, 24)
if _, err := rand.Read(b); err != nil {
log.Fatal(err)
}
return fmt.Sprintf("%x", b)
}
// IsSessionID checks if the string is a session id.
func IsSessionID(s string) bool {
if len(s) != 48 {
return false
}
return IsHex(s)
}