Merge branch '4-issue' into 'main'
Add genereate password Closes #4 See merge request h6n/tools!2
This commit is contained in:
commit
c97517ba6c
7 changed files with 119 additions and 0 deletions
46
.gitlab-ci.yml
Normal file
46
.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
default:
|
||||
image: debian:11
|
||||
|
||||
stages:
|
||||
- build
|
||||
- publish
|
||||
- release
|
||||
|
||||
build:
|
||||
stage: build
|
||||
image: golang:1.21-alpine
|
||||
before_script:
|
||||
- apk update && apk add --no-cache make git
|
||||
script:
|
||||
- make build_password
|
||||
artifacts:
|
||||
paths:
|
||||
- ./bin/*
|
||||
|
||||
publish_main:
|
||||
stage: publish
|
||||
image: golang:1.21-alpine
|
||||
variables:
|
||||
VER: latest
|
||||
before_script:
|
||||
- apk update && apk add --no-cache make git curl
|
||||
script:
|
||||
- make publish_password
|
||||
needs:
|
||||
- build
|
||||
only:
|
||||
- main
|
||||
|
||||
release_tag:
|
||||
stage: publish
|
||||
image: golang:1.21-alpine
|
||||
variables:
|
||||
VER: ${CI_COMMIT_TAG}
|
||||
before_script:
|
||||
- apk update && apk add --no-cache make git curl
|
||||
script:
|
||||
- make publish_password
|
||||
needs:
|
||||
- build
|
||||
only:
|
||||
- tags
|
||||
28
Makefile
Normal file
28
Makefile
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
ARCH := amd64 arm64
|
||||
OS := linux windows darwin
|
||||
NAME := password
|
||||
VERSION := $(shell git describe)
|
||||
BUILD := $(shell git rev-parse HEAD)
|
||||
|
||||
LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD}"
|
||||
|
||||
.PHONY: all build
|
||||
|
||||
all: build
|
||||
|
||||
build_password:
|
||||
$(foreach GOOS, ${OS},\
|
||||
$(foreach GOARCH, ${ARCH}, \
|
||||
$(shell CGO_ENABLED=0 go build -v -o bin/${NAME} ./golang/cmd/passwordhash;cd bin/;[ "${GOOS}" = "windows" ] && mv ${NAME} ${NAME}.exe;tar czf ${NAME}_${GOOS}_${GOARCH}.tar.gz *;rm -f ${NAME} ${NAME}.exe) \
|
||||
))
|
||||
|
||||
publish_password:
|
||||
$(foreach GOOS, ${OS},\
|
||||
$(foreach GOARCH, ${ARCH}, \
|
||||
$(curl --silent --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/${NAME}_${GOOS}_${GOARCH}.tar.gz "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${NAME}/${VER}/${NAME}_${GOOS}_${GOARCH}.tar.gz") \
|
||||
))
|
||||
|
||||
clean:
|
||||
rm -rf bin
|
||||
|
||||
re: clean all
|
||||
3
go.work
Normal file
3
go.work
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
go 1.21.8
|
||||
|
||||
use ./golang
|
||||
4
go.work.sum
Normal file
4
go.work.sum
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
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