2 Commits
Author SHA1 Message Date
Matt Baer ce8cb5ee19 Use #writefreely badge, not Slack 2019-01-10 21:42:25 -05:00
Matt Baer 5631982c2b Support creating word-ish password
This adds the NewWordish() func
2019-01-10 20:46:03 -05:00
3 changed files with 72 additions and 8 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ Write.as web core
================= =================
[![GoDoc](https://godoc.org/github.com/writeas/web-core?status.svg)](https://godoc.org/github.com/writeas/web-core) [![GoDoc](https://godoc.org/github.com/writeas/web-core?status.svg)](https://godoc.org/github.com/writeas/web-core)
[![Build Status](https://travis-ci.org/writeas/web-core.svg)](https://travis-ci.org/writeas/web-core) [![Build Status](https://travis-ci.org/writeas/web-core.svg)](https://travis-ci.org/writeas/web-core)
[![Public Slack discussion](http://slack.write.as/badge.svg)](http://slack.write.as/) [![#writefreely on freenode](https://img.shields.io/badge/freenode-%23writefreely-blue.svg)](http://webchat.freenode.net/?channels=writefreely)
[![Discuss on our forum](https://img.shields.io/discourse/https/discuss.write.as/users.svg?label=forum)](https://discuss.write.as/c/development) [![Discuss on our forum](https://img.shields.io/discourse/https/discuss.write.as/users.svg?label=forum)](https://discuss.write.as/c/development)
web-core holds components of the [Write.as](https://write.as) web application. web-core holds components of the [Write.as](https://write.as) web application.
+7 -7
View File
@@ -1,4 +1,4 @@
// Package passgen generates random, unmemorable passwords. // Package passgen generates random passwords.
// //
// Example usage: // Example usage:
// //
@@ -19,20 +19,20 @@ const DefLen = 20
// DefChars is the default set of characters used in the password. // DefChars is the default set of characters used in the password.
var DefChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()- _=+,.?/:;{}[]`~") var DefChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()- _=+,.?/:;{}[]`~")
// New returns a random password of the default length with the default set of // New returns a random, unmemorable password of the default length with the
// characters. // default set of characters.
func New() string { func New() string {
return NewLenChars(DefLen, DefChars) return NewLenChars(DefLen, DefChars)
} }
// NewLen returns a random password of the given length with the default set // NewLen returns a random, unmemorable password of the given length with the
// of characters. // default set of characters.
func NewLen(length int) string { func NewLen(length int) string {
return NewLenChars(length, DefChars) return NewLenChars(length, DefChars)
} }
// NewLenChars returns a random password of the given length with the given // NewLenChars returns a random, unmemorable password of the given length with
// set of characters. // the given set of characters.
func NewLenChars(length int, chars []byte) string { func NewLenChars(length int, chars []byte) string {
if length == 0 { if length == 0 {
return "" return ""
+64
View File
@@ -0,0 +1,64 @@
package passgen
import (
"crypto/rand"
"math/big"
)
var (
ar = []rune("aA4")
cr = []rune("cC")
er = []rune("eE3")
fr = []rune("fF")
gr = []rune("gG")
hr = []rune("hH")
ir = []rune("iI1")
lr = []rune("lL")
nr = []rune("nN")
or = []rune("oO0")
rr = []rune("rR")
sr = []rune("sS5")
tr = []rune("tT7")
remr = []rune("bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ0123456789")
)
// NewWordish generates a password made of word-like words.
func NewWordish() string {
b := []rune{}
b = append(b, randLetter(cr))
b = append(b, randLetter(hr))
b = append(b, randLetter(ar))
b = append(b, randLetter(nr))
b = append(b, randLetter(gr))
b = append(b, randLetter(er))
b = append(b, randLetter(tr))
b = append(b, randLetter(hr))
b = append(b, randLetter(ir))
b = append(b, randLetter(sr))
b = append(b, randLetter(ar))
b = append(b, randLetter(fr))
b = append(b, randLetter(tr))
b = append(b, randLetter(er))
b = append(b, randLetter(rr))
b = append(b, randLetter(lr))
b = append(b, randLetter(or))
b = append(b, randLetter(gr))
b = append(b, randLetter(gr))
b = append(b, randLetter(ir))
b = append(b, randLetter(nr))
b = append(b, randLetter(gr))
b = append(b, randLetter(ir))
b = append(b, randLetter(nr))
for i := 0; i <= 7; i++ {
b = append(b, randLetter(remr))
}
return string(b)
}
func randLetter(l []rune) rune {
li, err := rand.Int(rand.Reader, big.NewInt(int64(len(l))))
if err != nil {
return rune(-1)
}
return l[li.Int64()]
}