23 lines
579 B
Go
23 lines
579 B
Go
|
|
// 密码哈希生成工具:用于生成 SQL 种子数据中的 bcrypt 密码哈希
|
|||
|
|
// 使用方式:go run ./tools/genhash
|
|||
|
|
package main
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"fmt"
|
|||
|
|
|
|||
|
|
"golang.org/x/crypto/bcrypt"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
func main() {
|
|||
|
|
// 需要生成哈希的明文密码列表(超管密码 + 演示账号密码)
|
|||
|
|
passwords := []string{"qiqi991012", "123456"}
|
|||
|
|
for _, p := range passwords {
|
|||
|
|
// 使用默认成本因子(10)生成 bcrypt 哈希
|
|||
|
|
hash, err := bcrypt.GenerateFromPassword([]byte(p), bcrypt.DefaultCost)
|
|||
|
|
if err != nil {
|
|||
|
|
panic(err)
|
|||
|
|
}
|
|||
|
|
fmt.Printf("%s => %s\n", p, string(hash))
|
|||
|
|
}
|
|||
|
|
}
|