From e5b041b6b5f5267eff83463051bbc54f8449e2d1 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Sat, 15 Jul 2017 12:27:10 -0700 Subject: [PATCH] go-aah/aah#37 IsAuthSchemesConfigured method added --- acrypto/password_encoder.go | 9 ++++++++- security.go | 10 ++++++++++ security_test.go | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/acrypto/password_encoder.go b/acrypto/password_encoder.go index 5beca7f..c17f1b7 100644 --- a/acrypto/password_encoder.go +++ b/acrypto/password_encoder.go @@ -7,7 +7,14 @@ package acrypto import "fmt" // PasswordEncoder interface is used to encode and compare given hash and password -// based chosen hashing type. Such as `bcrypt`, `sha1`, `sha256`, `sha512` and `md5`. +// based chosen hashing type. Such as `bcrypt`, `scrypt`, `pbkdf2`, `sha1`, `sha256`, +// `sha512` and `md5`. +// +// Currently `bcrypt` is supported by aah framework, remaining encoders are `upcoming`. +// +// Caution: If you're using an unsecure hashing it may not be secured for your +// application. Consider using `bcrypt`, `scrypt`, or `pbkdf2`. Good read about +// hashing security - https://crackstation.net/hashing-security.htm type PasswordEncoder interface { Compare(hash, password []byte) bool } diff --git a/security.go b/security.go index db87565..f24ef18 100644 --- a/security.go +++ b/security.go @@ -110,6 +110,16 @@ func (m *Manager) AddAuthScheme(name string, authScheme scheme.Schemer) error { return nil } +// IsAuthSchemesConfigured method true if one or more auth scheme is configured in +// security.conf under `security.auth_schemes { ... }` +func (m *Manager) IsAuthSchemesConfigured() bool { + return len(m.authSchemes) != 0 +} + +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +// Package methods +//___________________________________ + // AcquireSubject method gets the subject from pool. func AcquireSubject() *Subject { return subjectPool.Get().(*Subject) diff --git a/security_test.go b/security_test.go index 472b62a..a33f57d 100644 --- a/security_test.go +++ b/security_test.go @@ -21,6 +21,7 @@ func TestSecurityInit(t *testing.T) { sec := New() err = sec.Init(cfg) assert.Nil(t, err) + assert.True(t, sec.IsAuthSchemesConfigured()) // Add auth scheme err = sec.AddAuthScheme("myauth", nil)