diff --git a/.gitignore b/.gitignore index af63df9..8c1fd79 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,6 @@ # Go workspace file go.work -.env \ No newline at end of file +.env +.idea/* +!.idea/copyright \ No newline at end of file diff --git a/.idea/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml deleted file mode 100644 index 02b915b..0000000 --- a/.idea/git_toolbox_prj.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/go-crypto.iml b/.idea/go-crypto.iml deleted file mode 100644 index 5e764c4..0000000 --- a/.idea/go-crypto.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 8d490d6..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 29520ab..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - \ No newline at end of file diff --git a/crypto.go b/crypto.go index 583ca6d..b684869 100644 --- a/crypto.go +++ b/crypto.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) Portalnesia - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + * Written by Putu Aditya + */ + package crypto import ( @@ -12,16 +19,18 @@ import ( "github.com/mergermarket/go-pkcs7" ) -type CryptoKey struct { +type Crypto struct { key []byte } -func New(secret string) CryptoKey { +// New initialize Crypto instance +func New(secret string) Crypto { key := []byte(secret) - return CryptoKey{key: key} + return Crypto{key: key} } -func (crypto CryptoKey) Encrypt(data string) (string, error) { +// Encrypt encrypt data +func (c Crypto) Encrypt(data string) (string, error) { plainText := []byte(data) plainText, err := pkcs7.Pad(plainText, aes.BlockSize) @@ -34,7 +43,7 @@ func (crypto CryptoKey) Encrypt(data string) (string, error) { return "", err } - block, err := aes.NewCipher(crypto.key) + block, err := aes.NewCipher(c.key) if err != nil { return "", err } @@ -54,7 +63,8 @@ func (crypto CryptoKey) Encrypt(data string) (string, error) { return encrypted, nil } -func (crypto CryptoKey) Decrypt(encrypted string) (string, error) { +// Decrypt decrypt data +func (c Crypto) Decrypt(encrypted string) (string, error) { if len(encrypted) <= 0 { return "", nil } @@ -68,7 +78,7 @@ func (crypto CryptoKey) Decrypt(encrypted string) (string, error) { return "", err } - block, err := aes.NewCipher(crypto.key) + block, err := aes.NewCipher(c.key) if err != nil { return "", err } diff --git a/crypto_test.go b/crypto_test.go index c6405f4..8957484 100644 --- a/crypto_test.go +++ b/crypto_test.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) Portalnesia - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + * Written by Putu Aditya + */ + package crypto import ( diff --git a/password.go b/password.go index ceee03b..b6765b3 100644 --- a/password.go +++ b/password.go @@ -1,9 +1,17 @@ +/* + * Copyright (c) Portalnesia - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + * Written by Putu Aditya + */ + package crypto import ( "golang.org/x/crypto/bcrypt" ) +// HashPassword hash password with bcrypt func HashPassword(p string) string { password := []byte(p) @@ -14,10 +22,8 @@ func HashPassword(p string) string { return string(hashed) } -func ComparePassword(p string, s string) bool { - password := []byte(p) - hashed := []byte(s) - - err := bcrypt.CompareHashAndPassword(hashed, password) +// ComparePassword compare password with saved hash password +func ComparePassword(password string, hasedPassword string) bool { + err := bcrypt.CompareHashAndPassword([]byte(hasedPassword), []byte(password)) return err == nil } diff --git a/password_test.go b/password_test.go index bdf4382..2077a39 100644 --- a/password_test.go +++ b/password_test.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) Portalnesia - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + * Written by Putu Aditya + */ + package crypto import (