Sign inSign up

chai2010/pwdgen

By chai2010

•Updated almost 9 years ago

Password generator

Image
1

912

chai2010/pwdgen repository overview

⁠Password Generator

Password generator, support export KeePass 1.x⁠ and 1Passworld⁠ format csv file.

AppDoc: http://godoc.org/github.com/chai2010/pwdgen⁠

⁠Install in Docker

docker run --rm -it chai2010/pwdgen -h

⁠Install with go get

go get github.com/chai2010/pwdgen

⁠Usage

$ pwdgen id0
$ pwdgen id0 id1 id2

$ pwdgen -salt=site0 id0
$ pwdgen -salt=site0 id0 id1 id2

$ pwdgen -encrypt-key=111 id0
$ pwdgen -encrypt-key=111 id0 id1 id2

$ pwdgen -encrypt-key=111 -salt=site0 id0 id1
$ pwdgen -encrypt-key=111 -salt=site0 id0 id1
$ pwdgen -encrypt-key=111 -salt=site0 id0 id1

$ # Generate config.ini template
$ pwdgen -gen-config=config.ini

# KeePass: See config.ini
# output: *.ini -> *.keepass1x.csv
pwdgen -keepass-config=config.ini
pwdgen -keepass-config=config.ini -encrypt-key=111

# 1password: See config.ini
# output: *.ini -> *.1password.csv
pwdgen -one-password-config=config.ini
pwdgen -one-password-config=config.ini -encrypt-key=111

$ pwdgen -version
$ pwdgen -help
$ pwdgen -h

⁠Use in Go

package main

import (
	"fmt"
	pwdgen "github.com/chai2010/pwdgen/pwdgen"
)
func main() {
	fmt.Println(pwdgen.PwdGen("id0", "site0", "111", "fuckcsdn"))
	// Output: 2jNXfMGoXTSK9pFS
}

⁠Algorithm

Default:

base58(sha512(md5hex(encryptKey+encryptSalt)+siteId+siteSalt))[0:16]

Other:

PasswordLength := 4~64, default is 16
PasswordType := number|alpha|ALPHA|base32|BASE32|base58, default is base58

Length := PasswordLength
Encoding := PasswordType

Encoding(sha512(md5hex(encryptKey+encryptSalt)+siteId+siteSalt))[0:Length]

alpha, ALPHA encoder:

func PwdGen(
	siteId, flagSiteSalt,
	flagEncryptKey, flagEncryptSalt string,
	encType EncoderType, length int,
) (string, error) {
	...

	alphabet := "abcdefghijklmnopqrstuvwxyz"
	if encType == EncoderType_AlphaUpper {
		alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	}

	x := new(big.Int).SetBytes(shaSum) // shaSum is big-endian
	y := big.NewInt(int64(len(alphabet)))
	m := new(big.Int)

	var buf [256]byte
	var idx = len(buf)

	for x.Sign() > 0 {
		x, m = x.DivMod(x, y, m)
		buf[idx-1] = byte(alphabet[int32(m.Int64())])
		idx--
	}

	pwd := string(buf[idx:][0:length])
	return pwd, nil

	...
}

⁠Screenshots

Command Line

KeePass 2.x

1Passworld 4

⁠Reference

Tag summary

Content type

Image

Digest

Size

2.8 MB

Last updated

almost 9 years ago

docker pull chai2010/pwdgen