Files
HY2XS_flamy/apps/cmd/reset.go
T

52 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"github.com/spf13/cobra"
"hy2xs-admin/dao"
"hy2xs-admin/util"
"os"
)
var resetCmd = &cobra.Command{
Use: "reset",
Short: "Reset username and password",
Long: "Reset username and password.",
Run: runReset,
}
func init() {
rootCmd.AddCommand(resetCmd)
}
func runReset(cmd *cobra.Command, args []string) {
username, err := util.RandomString(6)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
password, err := util.RandomString(6)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if err = dao.InitSqliteDB(); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if err = dao.UpdateAccount([]int64{1}, map[string]interface{}{
"username": username,
"pass": util.SHA224String(password),
"con_pass": fmt.Sprintf("%s.%s", username, password)}); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if err = dao.CloseSqliteDB(); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
fmt.Println(fmt.Sprintf("HY2XS admin Login Username: %s", username))
fmt.Println(fmt.Sprintf("HY2XS admin Login Password: %s", password))
fmt.Println(fmt.Sprintf("HY2XS admin Connection Password: %s", fmt.Sprintf("%s.%s", username, password)))
}