server/core/auth.go
Nick Craig-Wood c28a288338 Factor into server and driver directories (#120)
Factor into core and driver directories

The change factors the pure server implementation into the "core"
directory and factors the file driver into "driver/file" and the minio
driver into "driver/minio".

This means that users of this library can import goftp.io/server/core
without having to import the file and minio drivers which may not be
needed.

This also adds a compatibility layer which exports all the types,
functions and variables that were exported at the top level.

This means this change should be 100% backwards compatible.

Fixes #116

Co-authored-by: Nick Craig-Wood <nick@craig-wood.com>
Reviewed-on: goftp/server#120
2020-07-07 16:02:27 +00:00

34 lines
825 B
Go

// Copyright 2018 The goftp Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package core
import (
"crypto/subtle"
)
// Auth is an interface to auth your ftp user login.
type Auth interface {
CheckPasswd(string, string) (bool, error)
}
var (
_ Auth = &SimpleAuth{}
)
// SimpleAuth implements Auth interface to provide a memory user login auth
type SimpleAuth struct {
Name string
Password string
}
// CheckPasswd will check user's password
func (a *SimpleAuth) CheckPasswd(name, pass string) (bool, error) {
return constantTimeEquals(name, a.Name) && constantTimeEquals(pass, a.Password), nil
}
func constantTimeEquals(a, b string) bool {
return len(a) == len(b) && subtle.ConstantTimeCompare([]byte(a), []byte(b)) == 1
}