Skip to content

hedhyw/go-psw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-psw

Version Build Status Go Report Card Coverage Status PkgGoDev

A tiny golang tool for generating a crypto-random password in a terminal.

Golang logo

Installation

go install github.com/hedhyw/go-psw/cmd/psw@latest

Usage

psw [LENGTH] [CHARS_PATTERN]

# Just generate a secure-random password:
psw

# Generate a password of length 10:
psw 10

# Generate only with given pattern (next example will print [a-zA-Z]):
psw 10 aA

# Special case (next example will print only [ёàは]):
psw 10 ёàは

Using as a library

package main

import (
	"fmt"
	"log"

	"github.com/hedhyw/go-psw/pkg/v1/consts"
	"github.com/hedhyw/go-psw/pkg/v1/generator"
)

func main() {
	g := generator.NewCryptoRandGenerator()

	chars, err := g.GeneratePassword(
		consts.Digits+consts.LowerLetters, // Chars to use.
		10,                                // Password length.
	)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(chars)
}

License

See License.