mirror of
https://github.com/gmemstr/pogo.git
synced 2024-09-19 17:21:10 +01:00
Added crypto-secure password generation, old method was _not_ random
This commit is contained in:
parent
7ccba66a11
commit
7375d2846a
Binary file not shown.
31
setup.go
31
setup.go
|
@ -3,12 +3,13 @@ package main
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -16,14 +17,21 @@ import (
|
||||||
"github.com/google/go-github/github"
|
"github.com/google/go-github/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RandomString(n int) string {
|
func GenerateRandomBytes(n int) ([]byte, error) {
|
||||||
var letter = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-={}[]")
|
b := make([]byte, n)
|
||||||
|
_, err := rand.Read(b)
|
||||||
b := make([]rune, n)
|
if err != nil {
|
||||||
for i := range b {
|
return nil, err
|
||||||
b[i] = letter[rand.Intn(len(letter))]
|
|
||||||
}
|
}
|
||||||
return string(b)
|
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateRandomString returns a URL-safe, base64 encoded
|
||||||
|
// securely generated random string.
|
||||||
|
func GenerateRandomString(s int) (string, error) {
|
||||||
|
b, err := GenerateRandomBytes(s)
|
||||||
|
return base64.URLEncoding.EncodeToString(b), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup() {
|
func Setup() {
|
||||||
|
@ -45,7 +53,10 @@ func Setup() {
|
||||||
fmt.Println("Problem creating database! %v", err)
|
fmt.Println("Problem creating database! %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
text := RandomString(14)
|
text, err := GenerateRandomString(12)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error randomly generating password", err)
|
||||||
|
}
|
||||||
fmt.Println("Admin password: ", text)
|
fmt.Println("Admin password: ", text)
|
||||||
hash, err := bcrypt.GenerateFromPassword([]byte(text), 4)
|
hash, err := bcrypt.GenerateFromPassword([]byte(text), 4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -69,7 +80,7 @@ func Setup() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
res, _, err := client.GetLatestRelease(ctx, "gmemstr", "pogo-vue")
|
res, _, err := client.GetLatestRelease(ctx, "gmemstr", "pogo-vue")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Problem creating database! %v", err)
|
fmt.Println("Problem getting latest pogo-vue release! %v", err)
|
||||||
}
|
}
|
||||||
for i := 0; i < len(res.Assets); i++ {
|
for i := 0; i < len(res.Assets); i++ {
|
||||||
if res.Assets[i].GetName() == "webassets.zip" {
|
if res.Assets[i].GetName() == "webassets.zip" {
|
||||||
|
|
Loading…
Reference in a new issue