common

package
v0.0.0-...-896425a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package Name: common File Name: hasher.go Abstract: Hasher provides helper functions for encoding/decoding strings with the argon2 algorithm.

Author: Alejandro Modroño <alex@sureservice.es> Created: 07/12/2023 Last Updated: 07/24/2023

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Name: lib File Name: database.go Abstract: This file contains functions for validating the body of a request. Author: Alejandro Modroño <alex@sureservice.es> Created: 07/22/2023 Last Updated: 07/24/2023

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidHashException         = errors.New("The encoded hash is not in the correct format.")
	IncompatibleVersionException = errors.New("Incompatible version of argon2.")
)

======== ERRORS ========

View Source
var Hasher hasherT

the Hasher namespace

View Source
var Validation validationT

the Validation namespace

Functions

This section is empty.

Types

type Parameters

type Parameters struct {
	// contains filtered or unexported fields
}

Extracted from https://www.alexedwards.net/blog/how-to-hash-and-verify-passwords-with-argon2-in-go

The Argon2 algorithm accepts a number of configurable parameters:

  • Memory: The amount of memory used by the algorithm (in kibibytes).
  • Iterations: The number of iterations (or passes) over the memory.
  • Parallelism: The number of threads (or lanes) used by the algorithm.
  • Salt length: Length of the random salt. 16 bytes is recommended for password hashing.
  • Key length: Length of the generated key (or password hash). 16 bytes or more is recommended.

The memory and iterations parameters control the computational cost of hashing the password. The higher these figures are, the greater the cost of generating the hash. It also follows that the greater the cost will be for any attacker trying to guess the password.

But there's a balance that you need to strike. As you increase the cost, the time taken to generate the hash also increases. If you're generating the hash in response to a user action (like signing up or logging in to a website) then you probably want to keep the runtime to less than 500ms to avoid a negative user experience.

If the Argon2 algorithm is running on a machine with multiple cores, then one way to decrease the runtime without reducing the cost is to increase the parallelism parameter. This controls the number of threads that the work is spread across. There's an important thing to note here though: changing the value of the parallelism parameter changes the output of the algorithm. So — for example — running Argon2 with a parallelism parameter of 2 will result in a different password hash to running it with a parallelism parameter of 4.

type ValidationErrorMessage

type ValidationErrorMessage struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

ErrorMsg represents an error message returned by the API when the validation of the body parameters fails.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL