package main
import (
"fmt"
"log"
"math/rand"
"strconv"
"time"
"github.com/360EntSecGroup-Skylar/excelize/v2"
)
func checkErr(err error) {
if err != nil {
log.Fatal(err)
}
}
type userMgr struct {
account string
password string
file *excelize.File
}
func randNum(passwordBit int) []rune {
lowStr := []rune{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
highStr := []rune{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'H', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}
numStr := []rune{'2', '3', '4', '5', '6', '7', '8', '9'}
strSlice := [][]rune{lowStr, highStr, numStr}
//密码的集合切片
str := []rune{}
for {
<-time.Tick(time.Millisecond * 1)
rand.Seed(time.Now().UnixNano())
//随机排序一个数值切片
numSlice := rand.Perm(3)
//把这个随机的切片进行读取数值
for _, num := range numSlice {
//随机获取到strSlice的一个切片
numSlice2 := strSlice[num]
randRune := rand.Intn(len(numSlice2))
if len(str) != passwordBit {
str = append(str, numSlice2[randRune])
}
}
if len(str) == passwordBit {
break
}
}
return str
}
func (u *userMgr) create(userNum, i int) (slice []userMgr) {
for x := 0; x < userNum; x++ {
u.account = fmt.Sprintf("ykst%03d", x+1)
u.password = string(randNum(i))
slice = append(slice, *u)
}
return slice
}
func main() {
var n = 2
userAccount := userMgr{}
userAccount.file = excelize.NewFile()
userAccount.file.SetCellValue("Sheet1", "A1", "用户帐号")
userAccount.file.SetCellValue("Sheet1", "B1", "密码")
user := userAccount.create(10, 6)
for _, value := range user {
userAccount.file.SetCellValue("Sheet1", "A"+strconv.Itoa(n), value.account)
userAccount.file.SetCellValue("Sheet1", "B"+strconv.Itoa(n), value.password)
n++
}
checkErr(userAccount.file.SaveAs("account.xlsx"))
}