浏览代码

document bcrypt support

Nicola Murino 6 年之前
父节点
当前提交
7dd03ee24e
共有 2 个文件被更改,包括 4 次插入7 次删除
  1. 1 1
      README.md
  2. 3 6
      dataprovider/sqlcommon.go

+ 1 - 1
README.md

@@ -137,7 +137,7 @@ Here is a full example showing the default config:
 For each account the following properties can be configured:
 For each account the following properties can be configured:
 
 
 - `username` 
 - `username` 
-- `password` used for password authentication. The password will be stored using argon2id hashing algo
+- `password` used for password authentication. For users created using SFTPGo REST API the password will be stored using argon2id hashing algo. SFTPGo supports checking passwords stored with bcrypt too. Currently, as fallback, there is a clear text password checking but you should not store passwords as clear text and this support could be removed at any time, so please don't depend on it. 
 - `public_key` used for public key authentication. At least one between password and public key is mandatory
 - `public_key` used for public key authentication. At least one between password and public key is mandatory
 - `home_dir` The user cannot upload or download files outside this directory. Must be an absolute path
 - `home_dir` The user cannot upload or download files outside this directory. Must be an absolute path
 - `uid`, `gid`. If sftpgo runs as root then the created files and directories will be assigned to this system uid/gid. Ignored on windows and if sftpgo runs as non root user: in this case files and directories for all SFTP users will be owned by the system user that runs sftpgo.
 - `uid`, `gid`. If sftpgo runs as root then the created files and directories will be assigned to this system uid/gid. Ignored on windows and if sftpgo runs as non root user: in this case files and directories for all SFTP users will be owned by the system user that runs sftpgo.

+ 3 - 6
dataprovider/sqlcommon.go

@@ -46,15 +46,12 @@ func sqlCommonValidateUserAndPass(username string, password string) (User, error
 				logger.Warn(logSender, "error comparing password with argon hash: %v", err)
 				logger.Warn(logSender, "error comparing password with argon hash: %v", err)
 				return user, err
 				return user, err
 			}
 			}
-
-		} else if strings.HasPrefix(user.Password, bcryptPwdPrefix){
-			err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password))
-			if err != nil {
+		} else if strings.HasPrefix(user.Password, bcryptPwdPrefix) {
+			if err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)); err != nil {
 				logger.Warn(logSender, "error comparing password with bcrypt hash: %v", err)
 				logger.Warn(logSender, "error comparing password with bcrypt hash: %v", err)
 				return user, err
 				return user, err
-			}else{
-				match = true
 			}
 			}
+			match = true
 		} else {
 		} else {
 			// clear text password match
 			// clear text password match
 			match = (user.Password == password)
 			match = (user.Password == password)