From 1157835a2959506210234dcaad966f9a15a0dcea Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 2 Mar 2017 10:32:20 +0000 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20perform=20cpu=20intensive=20ope?= =?UTF-8?q?rations=20in=20SQL=20parser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/define.go | 9 +++++++++ sql/login.go | 6 +----- sql/scope.go | 4 ---- 3 files changed, 10 insertions(+), 9 deletions(-) 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 }