diff --git a/db/define.go b/db/define.go index b77b072c..cb474099 100644 --- a/db/define.go +++ b/db/define.go @@ -15,10 +15,13 @@ package db import ( + "golang.org/x/crypto/bcrypt" + "github.com/abcum/surreal/sql" "github.com/abcum/surreal/util/item" "github.com/abcum/surreal/util/keys" "github.com/abcum/surreal/util/pack" + "github.com/abcum/surreal/util/rand" ) func (e *executor) executeDefineNamespaceStatement(ast *sql.DefineNamespaceStatement) (out []interface{}, err error) { @@ -48,6 +51,10 @@ func (e *executor) executeDefineDatabaseStatement(ast *sql.DefineDatabaseStateme func (e *executor) executeDefineLoginStatement(ast *sql.DefineLoginStatement) (out []interface{}, err error) { + ast.Code = rand.New(128) + + ast.Pass, _ = bcrypt.GenerateFromPassword(ast.Pass, bcrypt.DefaultCost) + if ast.Kind == sql.NAMESPACE { // Set the namespace @@ -122,6 +129,8 @@ func (e *executor) executeDefineTokenStatement(ast *sql.DefineTokenStatement) (o func (e *executor) executeDefineScopeStatement(ast *sql.DefineScopeStatement) (out []interface{}, err error) { + ast.Code = rand.New(128) + // Set the namespace nkey := &keys.NS{KV: ast.KV, NS: ast.NS} nval := &sql.DefineNamespaceStatement{Name: ast.NS} diff --git a/sql/login.go b/sql/login.go index d63ea7d7..8c3a27ee 100644 --- a/sql/login.go +++ b/sql/login.go @@ -46,11 +46,7 @@ func (p *parser) parseDefineLoginStatement() (stmt *DefineLoginStatement, err er return nil, err } - if stmt.Pass, err = p.parseBcrypt(); err != nil { - return nil, err - } - - if stmt.Code, err = p.parseRand(); err != nil { + if stmt.Pass, err = p.parseBinary(); err != nil { return nil, err } diff --git a/sql/scope.go b/sql/scope.go index 17d80463..d1284615 100644 --- a/sql/scope.go +++ b/sql/scope.go @@ -55,10 +55,6 @@ func (p *parser) parseDefineScopeStatement() (stmt *DefineScopeStatement, err er } - if stmt.Code, err = p.parseRand(); err != nil { - return nil, err - } - if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil { return nil, err }