Skip to content

Commit 0507e60

Browse files
authored
[type:feat] password generate strategy submit (#83)
* feat:password generate strategy submit * Update openapi.go feat:update user to admin * feat: update md5 usage mode * feat: Code formatting * feat: add file license
1 parent 86eb84a commit 0507e60

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

internal/util/passwordutil.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2022, AcmeStack
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package util
19+
20+
import (
21+
"github.com/acmestack/godkits/gox/cryptox/md5x"
22+
)
23+
24+
// EncryptPassword Password generation Policy
25+
// @param password string
26+
// @param salt string
27+
// @return string
28+
func EncryptPassword(password, salt string) string {
29+
return md5x.Md5x(password + salt)
30+
}

internal/util/passwordutil_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2022, AcmeStack
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package util
19+
20+
import (
21+
"testing"
22+
)
23+
24+
// EncryptPassword Password generation Policy Test
25+
func TestEncryptPassword(t *testing.T) {
26+
password := "admin"
27+
salt := "07929137ab07437c933d6992321ef9fd"
28+
29+
encryptPassword := EncryptPassword(password, salt)
30+
31+
// login
32+
password = "admin"
33+
encryptPasswordLogin := EncryptPassword(password, salt)
34+
if encryptPasswordLogin != encryptPassword {
35+
t.Errorf("TestEncryptPassword() Login failed salt = %v, password %v", salt, password)
36+
}
37+
}

0 commit comments

Comments
 (0)