Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "bytes"
- "flag"
- "io"
- "os"
- )
- // StrongChars point to some strong chars for password
- var StrongChars = []byte{'!', '_', '-', '&', '?'}
- func isStrongChar(b byte) bool {
- for _, c := range StrongChars {
- if c == b {
- return true
- }
- }
- return false
- }
- func main() {
- n := flag.Int("n", 100, "byte number")
- flag.Parse()
- file, err := os.OpenFile("/dev/urandom", os.O_RDONLY, 644)
- if err != nil {
- panic(err)
- }
- buff := make([]byte, *n)
- reader := bufio.NewReader(file)
- for *n > 0 {
- b, err := reader.ReadByte()
- if err != nil {
- continue
- }
- if (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9') || isStrongChar(b) {
- *n--
- buff[*n] = b
- }
- }
- buff[len(buff)-1] = '\n'
- io.Copy(os.Stdout, bytes.NewReader(buff))
- }
Add Comment
Please, Sign In to add comment