Example #1
0
        /// <summary>
        /// PASS Command - RFC 959 - Section 4.1.1
        /// <para>密码</para>
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        private Response Password(string password)
        {
            FtpUser user = FtpUser.Validate((FtpServer)CurrentServer, _username, password);

            if (user != null && user.UserGroup == null)
            {
                user.UserGroup = ((FtpServer)CurrentServer).UserGroups["anonymous"];
            }
            if (user != null && user.UserGroup != null && user.UserGroup.Auth == AuthType.SSL && _sslEnabled == false)    //只能通过SSL加密登录
            {
                user = null;
            }
            if (user != null)
            {
                //if (!string.IsNullOrEmpty(user.TwoFactorSecret))
                //{
                //    _password = password;

                //    return GetResponse(FtpResponses.NEED_VERIFICATION);
                //}
                //else
                //{
                _currentUser = user;

                ConnectionInfo.User      = user.UserName;
                ConnectionInfo.UserGroup = user.GroupName;

                _virtualFileSystem = new VirtualFileSystem(((FtpServer)CurrentServer).Config, user.UserGroup);
                //TODO:引入新的虚拟文件系统

                if (_currentUser.IsAnonymous)
                {
                    _performanceCounter.IncrementAnonymousUsers();
                }
                else
                {
                    _performanceCounter.IncrementNonAnonymousUsers();
                }

                if (((FtpServer)CurrentServer).Config.LogInWelcome != null && !_sslEnabled)
                {
                    Write(new Response {
                        Code = "230-", Text = "Logged In"
                    });
                    foreach (var welcome in ((FtpServer)CurrentServer).Config.LogInWelcome)
                    {
                        Write(new Response {
                            Code = "", Text = welcome ?? ""
                        });
                    }
                }
                return(GetResponse(FtpResponses.LOGGED_IN));
                //}
            }
            else
            {
                return(GetResponse(FtpResponses.NOT_LOGGED_IN));
            }
        }
Example #2
0
        public void AddUser(string username, string password, string groupname, int maxconn = 4096)
        {
            FtpUser u;

            if (!UserGroups.ContainsKey(groupname.ToLower()))
            {
                u = new FtpUser(username, "anonymous", maxconn, password);
            }
            else
            {
                u = new FtpUser(username, groupname.ToLower(), maxconn, password, password);
            }

            if (Users.ContainsKey(username.ToLower()))
            {
                Users[username.ToLower()] = u;
            }
            else
            {
                Users.Add(username.ToLower(), u);
            }
            return;
        }