github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume2/section6/gopherfaceauth/common/authenticate/authenticate.go (about)

     1  package authenticate
     2  
     3  import (
     4  	"log"
     5  	"strings"
     6  
     7  	"github.com/EngineerKamesh/gofullstack/volume2/section6/gopherfaceauth/common"
     8  	"github.com/EngineerKamesh/gofullstack/volume2/section6/gopherfaceauth/common/utility"
     9  )
    10  
    11  func VerifyCredentials(e *common.Env, username string, password string) bool {
    12  
    13  	u, err := e.DB.GetUser(username)
    14  	if u == nil {
    15  		return false
    16  	}
    17  
    18  	if err != nil {
    19  		log.Print(err)
    20  	}
    21  
    22  	if strings.ToLower(username) == strings.ToLower(u.Username) && utility.SHA256OfString(password) == u.PasswordHash {
    23  		log.Println("Successful login attempt from user: ", u.Username)
    24  		return true
    25  	} else {
    26  		log.Println("Unsuccessful login attempt from user: ", u.Username)
    27  		return false
    28  	}
    29  
    30  }