Package ch.bztf.m226blb1.Auth
Class Credentials
java.lang.Object
ch.bztf.m226blb1.Auth.Credentials
The class for validating parameters and creating API-Keys.
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
containsNumber
(String value) Checks if the string contains a digit.static int
extractLimit
(Optional<Integer> limit) Extracts and validates thelimit
to a integer.static String
generateApiKey
(@NonNull AuthAccount account) Creates an API-key for the givenaccount
.static boolean
isValidUsername
(String username) Checks if the username is valid.static void
validateApiKey
(String apiKey) Validates if theapi key
is valid.static void
validateCredentials
(@NonNull AuthAccount auth)
-
Method Details
-
generateApiKey
Creates an API-key for the givenaccount
.- Parameters:
account
- the account to create the API key for.- Returns:
- an
API-Key
generated with the givenemail
,password
and thecurrent time
- See Also:
-
SHA-512 hasher
-
validateApiKey
Validates if theapi key
is valid.- Parameters:
apiKey
- the api key to validate- Throws:
javax.validation.ValidationException
- if the api key is not valid
-
validateCredentials
public static void validateCredentials(@NonNull @NonNull AuthAccount auth) throws javax.validation.ValidationException -
extractLimit
Extracts and validates thelimit
to a integer.- Parameters:
limit
- the limit to extract and validate- Returns:
- the extracted limit
- API Note:
- The default limit is
10
.
-
containsNumber
Checks if the string contains a digit.- Parameters:
value
- the string to be checked- Returns:
true
if the string contains a digit
-
isValidUsername
Checks if the username is valid.- Parameters:
username
- the username to be checked- Returns:
true
if the username is valid
-