mirror of https://github.com/gophish/gophish
Caused API key to be generated dynamically for admin user. Fixes #60
parent
b3fe840999
commit
fc6d556742
|
@ -57,7 +57,6 @@ func Register(r *http.Request) (bool, error) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
fmt.Println("Made it here!")
|
|
||||||
u = models.User{}
|
u = models.User{}
|
||||||
//If we've made it here, we should have a valid username given
|
//If we've made it here, we should have a valid username given
|
||||||
//Let's create the password hash
|
//Let's create the password hash
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
|
||||||
"github.com/gophish/gophish/config"
|
"github.com/gophish/gophish/config"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
_ "github.com/mattn/go-sqlite3" // Blank import needed to import sqlite3
|
_ "github.com/mattn/go-sqlite3" // Blank import needed to import sqlite3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,6 +48,13 @@ type Response struct {
|
||||||
Data interface{} `json:"data"`
|
Data interface{} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy of auth.GenerateSecureKey to prevent cyclic import with auth library
|
||||||
|
func generateSecureKey() string {
|
||||||
|
k := make([]byte, 32)
|
||||||
|
io.ReadFull(rand.Reader, k)
|
||||||
|
return fmt.Sprintf("%x", k)
|
||||||
|
}
|
||||||
|
|
||||||
// Setup initializes the Conn object
|
// Setup initializes the Conn object
|
||||||
// It also populates the Gophish Config object
|
// It also populates the Gophish Config object
|
||||||
func Setup() error {
|
func Setup() error {
|
||||||
|
@ -77,8 +87,8 @@ func Setup() error {
|
||||||
initUser := User{
|
initUser := User{
|
||||||
Username: "admin",
|
Username: "admin",
|
||||||
Hash: "$2a$10$IYkPp0.QsM81lYYPrQx6W.U6oQGw7wMpozrKhKAHUBVL4mkm/EvAS", //gophish
|
Hash: "$2a$10$IYkPp0.QsM81lYYPrQx6W.U6oQGw7wMpozrKhKAHUBVL4mkm/EvAS", //gophish
|
||||||
ApiKey: "12345678901234567890123456789012",
|
|
||||||
}
|
}
|
||||||
|
initUser.ApiKey = generateSecureKey()
|
||||||
err = db.Save(&initUser).Error
|
err = db.Save(&initUser).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
|
|
Loading…
Reference in New Issue