コード例 #1
0
ファイル: credentialsmatcher.go プロジェクト: jalkanen/kuro
func (cm *PlainText) Match(token authc.AuthenticationToken, info authc.AuthenticationInfo) bool {
	var givenPwd []byte
	// FIXME: Don't ignore errors
	switch token.Credentials().(type) {
	case string:
		givenPwd = []byte(token.Credentials().(string))
	case []byte:
		givenPwd = token.Credentials().([]byte)
	}

	storedPwd, _ := info.Credentials().(string)

	return bytes.Equal(givenPwd, []byte(storedPwd))
}
コード例 #2
0
ファイル: credentialsmatcher.go プロジェクト: jalkanen/kuro
func (cm *Hashed) Match(token authc.AuthenticationToken, info authc.AuthenticationInfo) bool {
	hash := getHash(cm.hashAlgorithm)
	var creds []byte

	creds = token.Credentials().([]byte)

	if salt, ok := info.(authc.SaltedAuthenticationInfo); ok {
		hash.Write(salt.CredentialsSalt())
	}

	var i int32

	for i = 0; i < cm.hashIterations; i++ {
		io.Copy(hash, bytes.NewReader(creds))
	}

	final := hash.Sum(nil)

	return bytes.Equal(final, info.Credentials().([]byte))
}