github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume3/section5/gopherface/common/authenticate/authenticate.go (about)

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