Documentation ¶
Overview ¶
Package rnd provides random token generation and validation.
Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.
This program is free software: you can redistribute it and/or modify it under Version 3 of the GNU Affero General Public License (the "AGPL"): <https://docs.photoprism.app/license/agpl> This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. The AGPL is supplemented by our Trademark and Brand Guidelines, which describe how our Brand Assets may be used: <https://www.photoprism.app/trademark>
Feel free to send an email to hello@photoprism.app if you have questions, want to support our work, or just want to say hello.
Additional information can be found in our Developer Guide: <https://docs.photoprism.app/developer-guide/>
Index ¶
- Constants
- func AppPassword() string
- func AuthKey(issuer, accountName string) (key *otp.Key, err error)
- func AuthToken() string
- func Base36(length int) string
- func Base62(length int) string
- func Charset(length int, charset string) string
- func ClientSecret() string
- func ContainsUID(s []string, prefix byte) bool
- func CrcToken() string
- func GenerateUID(prefix byte) string
- func InvalidRefID(s string) bool
- func InvalidUID(s string, prefix byte) bool
- func IsAlnum(s string) bool
- func IsAppPassword(s string, verifyChecksum bool) bool
- func IsAuthAny(s string) bool
- func IsAuthToken(s string) bool
- func IsClientSecret(s string) bool
- func IsHex(s string) bool
- func IsMD5(s string) bool
- func IsRefID(s string) bool
- func IsSHA1(s string) bool
- func IsSHA224(s string) bool
- func IsSHA256(s string) bool
- func IsSHA384(s string) bool
- func IsSHA512(s string) bool
- func IsSessionID(id string) bool
- func IsUID(s string, prefix byte) bool
- func IsUUID(s string) bool
- func IsUnique(s string, prefix byte) bool
- func Name() string
- func NameN(n int) string
- func RandomBytes(n int) ([]byte, error)
- func RecoveryCode() (code string)
- func RefID(id string) string
- func SanitizeUUID(s string) string
- func SessionID(token string) string
- func Sha224(b []byte) string
- func Sha256(b []byte) string
- func Sha512(b []byte) string
- func UUID() string
- func ValidateCrcToken(s string) bool
- type Type
- func (t Type) CrcToken() bool
- func (t Type) EntityID() bool
- func (t Type) Equal(s string) bool
- func (t Type) Hash() bool
- func (t Type) NotEqual(s string) bool
- func (t Type) SHA() bool
- func (t Type) SHA1() bool
- func (t Type) SHA2() bool
- func (t Type) SessionID() bool
- func (t Type) String() string
- func (t Type) Unknown() bool
Constants ¶
const ( SessionIdLength = 64 AuthTokenLength = 48 AppPasswordLength = 27 AppPasswordSeparator = '-' )
const ( PrefixNone = byte(0) PrefixMixed = byte('*') )
const CharsetBase36 = checksum.CharsetBase36
const CharsetBase62 = checksum.CharsetBase62
const (
ClientSecretLength = 32
)
Variables ¶
This section is empty.
Functions ¶
func AppPassword ¶
func AppPassword() string
AppPassword generates a random, human-friendly authentication token that can also be used as password replacement for client applications. It is separated by 3 dashes for better readability and has a total length of 27 characters.
Example: OXiV72-wTtiL9-d04jO7-X7XP4p
func AuthKey ¶
AuthKey returns a randomly initialized, time-based one-time password key, e.g. for 2-factor authentication.
func AuthToken ¶
func AuthToken() string
AuthToken generates a random hexadecimal character token for authenticating client applications.
Examples: 9fa8e562564dac91b96881040e98f6719212a1a364e0bb25
func Base62 ¶
Base62 generates a random token containing upper and lower case letters as well as numbers.
func ClientSecret ¶
func ClientSecret() string
ClientSecret generates a random client secret containing 32 upper and lower case letters as well as numbers.
func ContainsUID ¶
ContainsUID checks if a slice of strings contains ContainsUID only.
func GenerateUID ¶
GenerateUID returns a unique id with prefix as string.
func InvalidRefID ¶
InvalidRefID checks if the reference ID is empty or invalid.
func InvalidUID ¶
InvalidUID checks if the UID is empty or invalid.
func IsAlnum ¶
IsAlnum returns true if the string only contains alphanumeric ascii chars without whitespace.
func IsAppPassword ¶
IsAppPassword checks if the string represents a valid app password.
func IsAuthToken ¶
IsAuthToken checks if the string represents a valid auth token.
func IsClientSecret ¶
IsClientSecret checks if the string represents a valid client secret.
func IsHex ¶
IsHex returns true if the string only contains hex numbers, dashes and letters without whitespace.
func IsMD5 ¶
IsMD5 checks if the string appears to be an MD5 hash. Example: 79054025255fb1a26e4bc422aef54eb4
func IsSHA1 ¶
IsSHA1 checks if the string appears to be a SHA1 hash. Example: de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3
func IsSHA224 ¶
IsSHA224 checks if the string appears to be a SHA224 hash. Example: d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f
func IsSHA256 ¶
IsSHA256 checks if the string appears to be a SHA256 hash. Example: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
func IsSHA384 ¶
IsSHA384 checks if the string appears to be a SHA384 hash. Example: 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b
func IsSHA512 ¶
IsSHA512 checks if the string appears to be a SHA512 hash. Example: cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
func IsSessionID ¶
IsSessionID checks if the string represents a valid session id.
func Name ¶
func Name() string
Name returns a pronounceable name consisting of a pet name and an adverb or adjective.
func NameN ¶
NameN returns a pronounceable name consisting of a random combination of adverbs, an adjective, and a pet name.
func RandomBytes ¶
RandomBytes returns cryptographically secure random bytes.
func RecoveryCode ¶
func RecoveryCode() (code string)
RecoveryCode returns a randomly created recovery code for e.g. for 2-factor authentication.
func SanitizeUUID ¶
SanitizeUUID normalizes UUIDs found in XMP or Exif metadata.
func UUID ¶
func UUID() string
UUID returns a random string based on RFC 4122 (UUID Version 4) or panics.
The strength of the UUID depends on the "crypto/rand" package.
func ValidateCrcToken ¶
ValidateCrcToken tests if the token string is valid.
Types ¶
type Type ¶
type Type string
Type represents a random id type.
const ( TypeEmpty Type = "empty" TypeMixed Type = "mixed" TypeUUID Type = "UUID" TypeUID Type = "UID" TypeRefID Type = "RID" TypeSessionID Type = "SID" TypeCrcToken Type = "CRC" TypeMD5 Type = "MD5" TypeSHA1 Type = "SHA1" TypeSHA224 Type = "SHA224" TypeSHA256 Type = "SHA256" TypeSHA384 Type = "SHA384" TypeSHA512 Type = "SHA512" TypeUnknown Type = "unknown" )
func ContainsType ¶
ContainsType checks if a slice of strings contains only random IDs of a given type and returns it.
func IdType ¶
IdType checks what kind of random ID a string contains and returns it along with the id prefix, if any.