v1.2.0: code: import password
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
f3079610ea
commit
cbe5e3ed63
5 changed files with 45 additions and 0 deletions
31
golang/cmd/passwordhash/main.go
Normal file
31
golang/cmd/passwordhash/main.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func HashPassword(password string) (string, error) {
|
||||
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
|
||||
return string(bytes), err
|
||||
}
|
||||
|
||||
func main() {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
fmt.Print("Enter a password : ")
|
||||
scanner.Scan()
|
||||
primary := scanner.Text()
|
||||
fmt.Print("Enter a password : ")
|
||||
scanner.Scan()
|
||||
second := scanner.Text()
|
||||
|
||||
if primary != second {
|
||||
fmt.Println("password do not match")
|
||||
return
|
||||
}
|
||||
hash, _ := HashPassword(primary)
|
||||
fmt.Println("La version hasher du password :", string(hash))
|
||||
}
|
||||
5
golang/go.mod
Normal file
5
golang/go.mod
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
module gitlab.g3e.fr/h6n/tools/golang
|
||||
|
||||
go 1.21.8
|
||||
|
||||
require golang.org/x/crypto v0.21.0 // indirect
|
||||
2
golang/go.sum
Normal file
2
golang/go.sum
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
|
||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||
Loading…
Add table
Add a link
Reference in a new issue