little-cui commented on code in PR #1365:
URL: 
https://github.com/apache/servicecomb-service-center/pull/1365#discussion_r1045565608


##########
pkg/privacy/password.go:
##########
@@ -33,23 +32,26 @@ const (
 
 var ScryptParams = scrypt.Params{N: 1024, R: 8, P: 1, SaltLen: 8, DKLen: 32}
 
-// HashPassword
-// Deprecated: use ScryptPassword, this is only for unit test to test 
compatible with old version
-func HashPassword(pwd string) (string, error) {
-       hash, err := bcrypt.GenerateFromPassword([]byte(pwd), 14)
-       if err != nil {
-               return "", err
-       }
-       return stringutil.Bytes2str(hash), nil
+// DefaultManager default manager
+var DefaultManager PasswordManager = &Password{}
+
+type PasswordManager interface {
+       EncryptPassword(pwd string) (string, error)
+       CheckPassword(hashedPwd, pwd string) bool
 }
-func ScryptPassword(pwd string) (string, error) {
+
+type Password struct {
+}
+
+func (p Password) EncryptPassword(pwd string) (string, error) {

Review Comment:
   应该是p *Password



##########
pkg/privacy/password.go:
##########
@@ -33,23 +32,26 @@ const (
 
 var ScryptParams = scrypt.Params{N: 1024, R: 8, P: 1, SaltLen: 8, DKLen: 32}
 
-// HashPassword
-// Deprecated: use ScryptPassword, this is only for unit test to test 
compatible with old version
-func HashPassword(pwd string) (string, error) {
-       hash, err := bcrypt.GenerateFromPassword([]byte(pwd), 14)
-       if err != nil {
-               return "", err
-       }
-       return stringutil.Bytes2str(hash), nil
+// DefaultManager default manager
+var DefaultManager PasswordManager = &Password{}
+
+type PasswordManager interface {
+       EncryptPassword(pwd string) (string, error)
+       CheckPassword(hashedPwd, pwd string) bool
 }
-func ScryptPassword(pwd string) (string, error) {
+
+type Password struct {

Review Comment:
   改成私有,小写passwordManager



##########
pkg/privacy/password_test.go:
##########
@@ -23,42 +23,9 @@ import (
 
        "github.com/apache/servicecomb-service-center/pkg/privacy"
        scrypt "github.com/elithrar/simple-scrypt"
-       "github.com/go-chassis/foundation/stringutil"
-       "github.com/stretchr/testify/assert"
        "golang.org/x/crypto/pbkdf2"
 )
 
-func TestHashPassword(t *testing.T) {

Review Comment:
   1、为什么要删除用例?
   2、请增加UT:test中使用mock的struct替换defaultmanager的测试



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to