mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-28 01:36:30 +00:00
5bbb969763
* remove repo for document tokens * remove schema for doc tokens * fix id template and generate cmd * schema updates * code gen * bump dependencies * fix broken migrations + add maintenance entry type * spelling * remove debug logger * implement repository layer * routes * API client * wip: maintenance log * remove depreciated call
37 lines
698 B
Go
37 lines
698 B
Go
package hasher
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
var enabled = true
|
|
|
|
func init() {
|
|
disableHas := os.Getenv("UNSAFE_DISABLE_PASSWORD_PROJECTION") == "yes_i_am_sure"
|
|
|
|
if disableHas {
|
|
fmt.Println("WARNING: Password protection is disabled. This is unsafe in production.")
|
|
enabled = false
|
|
}
|
|
}
|
|
|
|
func HashPassword(password string) (string, error) {
|
|
if !enabled {
|
|
return password, nil
|
|
}
|
|
|
|
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
|
|
return string(bytes), err
|
|
}
|
|
|
|
func CheckPasswordHash(password, hash string) bool {
|
|
if !enabled {
|
|
return password == hash
|
|
}
|
|
|
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
|
return err == nil
|
|
}
|