Exemplo n.º 1
0
func (a *Account) NewRandomPassword() (string, error) {
	pw := uniuri.NewLenChars(12, stdChars)
	b, e := bcrypt.GenerateFromPassword([]byte(pw), pwCost)
	if e != nil {
		return "", e
	}
	a.Password.Current = b
	a.Password.Set = time.Now()
	a.Password.Change = true
	return pw, nil
}
Exemplo n.º 2
0
func confWrite(config HandlerConfig) func(siteParams) (siteParams, Err) {

	return func(siteConfig siteParams) (siteParams, Err) {

		err := os.ErrExist
		var randPart, fileName string
		var f *os.File

		for os.IsExist(err) {
			randPart = uniuri.NewLenChars(config.subdomainLen, SubdomainChars)
			// pick again if you got something reserved
			if inArr(config.exclude, randPart) {
				continue
			}
			if inArr(config.exclude, randPart+DomainSep+config.baseURL) {
				continue
			}
			fileName = strings.Join([]string{
				strings.TrimRight(config.confPath, PathSep),
				PathSep,
				randPart,
				DomainSep,
				config.baseURL,
				DomainSep,
				strings.TrimLeft(config.confExt, DomainSep)}, "")
			f, err = os.Create(fileName)
		}

		siteConfig.ExtHost = strings.Join([]string{
			randPart,
			DomainSep,
			config.baseURL}, "")

		if err == os.ErrPermission {
			return siteParams{ExtHost: randPart}, &NewErr{Code: ErrFilePerm, value: fileName, deepErr: err}
		} else if err != nil {
			return siteParams{ExtHost: randPart}, &NewErr{Code: ErrFileUnexpect, value: fileName, deepErr: err}
		}

		tErr := config.confTempl.Execute(f, siteConfig)

		if err = f.Close(); err != nil {
			return siteParams{}, &NewErr{Code: ErrCloseFile, value: fileName, deepErr: err}
		}

		if tErr != nil {
			if err = os.Remove(fileName); err != nil {
				return siteParams{}, &NewErr{Code: ErrRemoveFile, value: fileName, deepErr: err}
			}
		}

		return siteConfig, nil
	}
}
Exemplo n.º 3
0
Arquivo: main.go Projeto: vdvm/passgen
func main() {
	p := flags.NewParser(&Opts, flags.Default)
	p.Name = "passgen"
	p.Usage = "[OPTIONS]"

	_, err := p.Parse()
	if err != nil {
		os.Exit(0)
	}

	if Opts.Special {
		StdChars = append(StdChars, SpChars...)
	}

	if Opts.Version {
		fmt.Println(Version)
		os.Exit(0)
	}

	s := uniuri.NewLenChars(Opts.Length, StdChars)
	fmt.Println(s)
}
Exemplo n.º 4
0
func generateBarename() string {
	return uniuri.NewLenChars(8, []byte("abcdefghijklmnopqrstuvwxyz0123456789"))
}
Exemplo n.º 5
0
func randomString(length int, chars []byte) string {
	return uniuri.NewLenChars(length, chars)
}