Commit 989bfcf4 authored by Mayuri Shinde's avatar Mayuri Shinde
Browse files

Constants added in constantmdl

parent e4c003a8
2 merge requests!23Devbranch to Master,!18Securitymdl :SecurityKeyCreator and PasswordSalt
Showing with 18 additions and 17 deletions
......@@ -30,3 +30,18 @@ const IDLECONNTIMEOUT = time.Second * 90
// TASKCOUNT is used as default task count in filepipe
const TASKCOUNT = 5
// constants used for CreateSecurityKey function in securitymdl
const (
MAX_RANDOM_STRING_LENGTH = 256
RANDOM_STRING_LENGTH = 16
NUMBERS_PERCENT = 10
SMALL_CHARS_PERCENT = 40
CAP_CHARS_PERCENT = 40
SPECIAL_CHARS_PERCENT = 10
CharSet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*+,-./:;<=>?@[]^_`{|}~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*+,-./:;<=>?@[]^_`{|}~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*@"
NUMBERS_SET = "0123456789"
SMALL_CHARS_SET = "abcdefghijklmnopqrstuvwxyz"
CAP_CHARS_SET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
SPECIAL_CHARS_SET = "!#$%&'()*+,-./:;<=>?@[]^_`{|}~"
)
......@@ -8,6 +8,7 @@ import (
"math/rand"
"time"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/constantmdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl"
"golang.org/x/crypto/bcrypt"
......@@ -169,28 +170,13 @@ func AESDecrypt(encodedData, key []byte) ([]byte, error) {
// return byteArray, nil
// }
// First
const (
MAX_RANDOM_STRING_LENGTH = 256
RANDOM_STRING_LENGTH = 16
NUMBERS_PERCENT = 10
SMALL_CHARS_PERCENT = 40
CAP_CHARS_PERCENT = 40
SPECIAL_CHARS_PERCENT = 10
charSet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*+,-./:;<=>?@[]^_`{|}~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*+,-./:;<=>?@[]^_`{|}~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*@"
numebersSet = "0123456789"
smallCharSet = "abcdefghijklmnopqrstuvwxyz"
capCharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
specialCharSet = "!#$%&'()*+,-./:;<=>?@[]^_`{|}~"
)
// CreateSecurityKey generates random string of given length
func CreateSecurityKey(keyLength int) (string, error) {
if keyLength <= MAX_RANDOM_STRING_LENGTH {
if keyLength <= constantmdl.MAX_RANDOM_STRING_LENGTH {
seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
b := make([]byte, keyLength)
for i := range b {
b[i] = charSet[seededRand.Intn(keyLength)]
b[i] = constantmdl.CharSet[seededRand.Intn(keyLength)]
}
return string(b), nil
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment