Skip to content

Instantly share code, notes, and snippets.

@kavirajk
Created July 15, 2016 11:29
Show Gist options
  • Save kavirajk/21588757af71a700ae64d2b62259fb2f to your computer and use it in GitHub Desktop.
Save kavirajk/21588757af71a700ae64d2b62259fb2f to your computer and use it in GitHub Desktop.
Reset password (unable to mock)
package main
import (
"flag"
"fmt"
"log"
"code.launchyard.com/root/aircto-backend/config"
"code.launchyard.com/root/aircto-backend/models"
"code.launchyard.com/root/aircto-backend/utils"
)
var (
email = flag.String("email", "", "user's email to reset the password")
password = flag.String("password", "", "new password")
)
func main() {
flag.Parse()
if *email == "" {
fmt.Print("email: ")
fmt.Scanln(email)
}
if *password == "" {
fmt.Print("new-password: ")
fmt.Scanln(password)
}
models.InitModel(config.DBDriver, fmt.Sprintf(config.DBDataSource))
user, err := models.GetUserByEmail(*email)
if err != nil {
log.Fatalf("error getting user: %v\n", err)
}
user.Password = utils.HashString(*password)
if err := user.Save(); err != nil {
log.Fatalf("error saving new password: %v\n", err)
}
fmt.Println("Password reset success.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment