详情请参考:http://asp2004.net/dvbbs/dispbbs.asp?boardid=6&id=287
数据库脚本:
/****** Object: Database host Script Date: 2004-12-24 13:16:31 ******/
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'host')
DROP DATABASE [host]
GO
CREATE DATABASE [host] ON (NAME = N'Host_Data', FILENAME = N'D:\wwwroot\host\database\host.mdf' , SIZE = 2, FILEGROWTH = 10%) LOG ON (NAME = N'Host_Log', FILENAME = N'D:\wwwroot\host\database\host_log.ldf' , SIZE = 9, FILEGROWTH = 10%)
COLLATE Chinese_PRC_CI_AS
GO
exec sp_dboption N'host', N'autoclose', N'false'
GO
exec sp_dboption N'host', N'bulkcopy', N'false'
GO
exec sp_dboption N'host', N'trunc. log', N'false'
GO
exec sp_dboption N'host', N'torn page detection', N'true'
GO
exec sp_dboption N'host', N'read only', N'false'
GO
exec sp_dboption N'host', N'dbo use', N'false'
GO
exec sp_dboption N'host', N'single', N'false'
GO
exec sp_dboption N'host', N'autoshrink', N'false'
GO
exec sp_dboption N'host', N'ANSI null default', N'false'
GO
exec sp_dboption N'host', N'recursive triggers', N'false'
GO
exec sp_dboption N'host', N'ANSI nulls', N'false'
GO
exec sp_dboption N'host', N'concat null yields null', N'false'
GO
exec sp_dboption N'host', N'cursor close on commit', N'false'
GO
exec sp_dboption N'host', N'default to local cursor', N'false'
GO
exec sp_dboption N'host', N'quoted identifier', N'false'
GO
exec sp_dboption N'host', N'ANSI warnings', N'false'
GO
exec sp_dboption N'host', N'auto create statistics', N'true'
GO
exec sp_dboption N'host', N'auto update statistics', N'true'
GO
use [host]
GO
/****** Object: Table [dbo].[GroupAccess] Script Date: 2004-12-24 13:16:31 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GroupAccess]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[GroupAccess]
GO
/****** Object: Table [dbo].[GroupAccounts] Script Date: 2004-12-24 13:16:31 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GroupAccounts]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[GroupAccounts]
GO
/****** Object: Table [dbo].[GroupIPAccess] Script Date: 2004-12-24 13:16:31 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GroupIPAccess]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[GroupIPAccess]
GO
/****** Object: Table [dbo].[UserAccess] Script Date: 2004-12-24 13:16:31 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserAccess]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[UserAccess]
GO
/****** Object: Table [dbo].[UserAccounts] Script Date: 2004-12-24 13:16:31 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserAccounts]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[UserAccounts]
GO
/****** Object: Table [dbo].[UserIPAccess] Script Date: 2004-12-24 13:16:31 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserIPAccess]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[UserIPAccess]
GO
/****** Object: Table [dbo].[GroupAccess] Script Date: 2004-12-24 13:16:34 ******/
CREATE TABLE [dbo].[GroupAccess] (
[IndexNo] [int] NULL ,
[UserName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Access] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
[GAid] [int] IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[GroupAccounts] Script Date: 2004-12-24 13:16:36 ******/
CREATE TABLE [dbo].[GroupAccounts] (
[UserName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Access] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
[Notes] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
[GAsId] [int] IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[GroupIPAccess] Script Date: 2004-12-24 13:16:36 ******/
CREATE TABLE [dbo].[GroupIPAccess] (
[IndexNo] [int] NULL ,
[UserName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Access] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
[GIpAid] [int] IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[UserAccess] Script Date: 2004-12-24 13:16:37 ******/
CREATE TABLE [dbo].[UserAccess] (
[IndexNo] [int] NULL ,
[UserName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Access] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
[UAid] [int] IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[UserAccounts] Script Date: 2004-12-24 13:16:37 ******/
CREATE TABLE [dbo].[UserAccounts] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[UserName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Password] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Disable] [bit] NOT NULL ,
[Access] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
[ChangePass] [bit] NOT NULL ,
[PassType] [tinyint] NOT NULL ,
[Expiration] [smalldatetime] NOT NULL ,
[ExpirationType] [tinyint] NOT NULL ,
[SKey] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[RelPaths] [bit] NOT NULL ,
[HomeDir] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
[MessageFile] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
[MaxUsers] [int] NOT NULL ,
[MaxUp] [int] NOT NULL ,
[MaxDown] [int] NOT NULL ,
[RatioUp] [int] NULL ,
[RatioDown] [int] NULL ,
[RatioCredit] [float] NULL ,
[RatioType] [tinyint] NULL ,
[QuotaEnable] [bit] NOT NULL ,
[QuotaMax] [int] NOT NULL ,
[QuotaCurrent] [int] NOT NULL ,
[Groups] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
[Privilege] [tinyint] NOT NULL ,
[LockHomeDir] [bit] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[UserIPAccess] Script Date: 2004-12-24 13:16:38 ******/
CREATE TABLE [dbo].[UserIPAccess] (
[IndexNo] [smallint] NULL ,
[UserName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Access] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
[UIpAid] [int] IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[GroupAccess] WITH NOCHECK ADD
CONSTRAINT [PK_GroupAccess] PRIMARY KEY CLUSTERED
(
[GAid]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[GroupAccounts] WITH NOCHECK ADD
CONSTRAINT [PK_GroupAccounts] PRIMARY KEY CLUSTERED
(
[GAsId]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[GroupIPAccess] WITH NOCHECK ADD
CONSTRAINT [PK_GroupIPAccess] PRIMARY KEY CLUSTERED
(
[GIpAid]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[UserAccess] WITH NOCHECK ADD
CONSTRAINT [PK_UserAccess] PRIMARY KEY CLUSTERED
(
[UAid]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[UserAccounts] WITH NOCHECK ADD
CONSTRAINT [PK_UserAccounts] PRIMARY KEY CLUSTERED
(
[id]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[UserIPAccess] WITH NOCHECK ADD
CONSTRAINT [PK_UserIPAccess] PRIMARY KEY CLUSTERED
(
[UIpAid]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[UserAccounts] WITH NOCHECK ADD
CONSTRAINT [DF_UserAccounts_Disable] DEFAULT (0) FOR [Disable],
CONSTRAINT [DF_UserAccounts_ChangePass] DEFAULT (1) FOR [ChangePass],
CONSTRAINT [DF_UserAccounts_PassType] DEFAULT (0) FOR [PassType],
CONSTRAINT [DF_UserAccounts_ExpirationType] DEFAULT (1) FOR [ExpirationType],
CONSTRAINT [DF_UserAccounts_RelPaths] DEFAULT (0) FOR [RelPaths],
CONSTRAINT [DF_UserAccounts_MaxUsers] DEFAULT ((-1)) FOR [MaxUsers],
CONSTRAINT [DF_UserAccounts_MaxUp] DEFAULT (0) FOR [MaxUp],
CONSTRAINT [DF_UserAccounts_MaxDown] DEFAULT (0) FOR [MaxDown],
CONSTRAINT [DF_UserAccounts_RatioUp] DEFAULT (1) FOR [RatioUp],
CONSTRAINT [DF_UserAccounts_RatioDown] DEFAULT (1) FOR [RatioDown],
CONSTRAINT [DF_UserAccounts_RatioCredit] DEFAULT (0) FOR [RatioCredit],
CONSTRAINT [DF_UserAccounts_RatioType] DEFAULT (0) FOR [RatioType],
CONSTRAINT [DF_UserAccounts_QuotaEnable] DEFAULT (1) FOR [QuotaEnable],
CONSTRAINT [DF_UserAccounts_QuotaMax] DEFAULT (0) FOR [QuotaMax],
CONSTRAINT [DF_UserAccounts_QuotaCurrent] DEFAULT (0) FOR [QuotaCurrent],
CONSTRAINT [DF_UserAccounts_Privilege] DEFAULT (0) FOR [Privilege],
CONSTRAINT [DF_UserAccounts_LockHomeDir] DEFAULT (1) FOR [LockHomeDir],
CONSTRAINT [IX_UserAccounts] UNIQUE NONCLUSTERED
(
[UserName]
) ON [PRIMARY]
GO
exec sp_addextendedproperty N'MS_Description', N'目录权限', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'Access'
GO
exec sp_addextendedproperty N'MS_Description', N'是否允许更改密码', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'ChangePass'
GO
exec sp_addextendedproperty N'MS_Description', N'帐号是否禁用', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'Disable'
GO
exec sp_addextendedproperty N'MS_Description', N'过期时间', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'Expiration'
GO
exec sp_addextendedproperty N'MS_Description', N'过期类型', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'ExpirationType'
GO
exec sp_addextendedproperty N'MS_Description', N'用户组', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'Groups'
GO
exec sp_addextendedproperty N'MS_Description', N'主目录', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'HomeDir'
GO
exec sp_addextendedproperty N'MS_Description', N'是否锁定在主目录', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'LockHomeDir'
GO
exec sp_addextendedproperty N'MS_Description', N'最大下载速率', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'MaxDown'
GO
exec sp_addextendedproperty N'MS_Description', N'最大上传速率', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'MaxUp'
GO
exec sp_addextendedproperty N'MS_Description', N'最大登陆用户数', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'MaxUsers'
GO
exec sp_addextendedproperty N'MS_Description', N'消息文件', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'MessageFile'
GO
exec sp_addextendedproperty N'MS_Description', N'密码类型', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'PassType'
GO
exec sp_addextendedproperty N'MS_Description', N'密码', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'Password'
GO
exec sp_addextendedproperty N'MS_Description', N'管理权限', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'Privilege'
GO
exec sp_addextendedproperty N'MS_Description', N'当前配额', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'QuotaCurrent'
GO
exec sp_addextendedproperty N'MS_Description', N'启用磁盘配额', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'QuotaEnable'
GO
exec sp_addextendedproperty N'MS_Description', N'最大配额', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'QuotaMax'
GO
exec sp_addextendedproperty N'MS_Description', N'下载比率', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'RatioDown'
GO
exec sp_addextendedproperty N'MS_Description', N'上传比率', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'RatioUp'
GO
exec sp_addextendedproperty N'MS_Description', N'用户名', N'user', N'dbo', N'table', N'UserAccounts', N'column', N'UserName'
GO
asp.net实现的代码:
using System;
using System.Web.Security;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace host
{
/// <summary>
/// ftp 的摘要说明。
/// </summary>
public class ftp
{
private SqlConnection conHost;
public string UserName;//用户名
public string Password;//密码
public bool Disable;//禁用帐号 true:禁用帐号 false:启用帐号
public string Access;//目录/IP访问规则
public byte PassType;//密码类型 0:规则密码 1:OTP S/KEY MD4 2:OTP S/KEY MD5
public bool ChangePass;//允许修改密码 true:允许 false:禁止
public DateTime Expiration;//过期时间
public byte ExpirationType;//过期类型 1:删除 2:禁用
public string SKey;
public bool RelPaths;//需要安全连接 true:需要 false:不需要
public string HomeDir;//主目录
public string MessageFile;//消息文件
public int MaxUsers;//最大用户数
public int MaxUp;//最大上传速率
public int MaxDown;//最大下载速率
public byte RatioType;//比率类型
public int RatioUp;//上传率
public int RatioDown;//下载率
public float RatioCredit;//比率信任
public bool QuotaEnable;//允许配额 true:允许 false:禁止
public int QuotaMax;//最大配额
public int QuotaCurrent;//当前配额
public string Groups;//用户组
public byte Privilege;//管理权限 0:没有权限 1:系统管理员 2:组管理员 3:域管理员 4:只读管理员
public bool LockHomeDir;//锁定于主目录 true:锁定 false:不锁定
public ftp()
{
//
// TODO: 在此处添加构造函数逻辑
//
UserName = "guest";
Password = "guest";
Disable = false;
Access = "";
PassType = 0;
ChangePass = true;
Expiration = DateTime.Now.Date;
ExpirationType = 1;
SKey = "";
RelPaths = false;
HomeDir = "";
MessageFile = "";
MaxUsers = 1;
MaxUp = 100 * 1024;//100K
MaxDown = 100 * 1024;//100K
RatioType = 0;
RatioUp = 1;
RatioDown = 1;
RatioCredit = 0;
QuotaEnable = true;
QuotaMax = 10 * 1024 * 1024;//10M
QuotaCurrent = 0;
Groups = "";
Privilege = 0;
LockHomeDir = true;
conHost = new SqlConnection( ConfigurationSettings.AppSettings["conString"] );
conHost.Open();
}
~ftp()
{
conHost.Close();
}
public void Add()
{
//添加帐号
SqlCommand cmdAdd = new SqlCommand( "insert into UserAccounts (UserName,Password,Disable,Access,ChangePass,PassType,Expiration,ExpirationType,SKey,RelPaths,HomeDir,MessageFile,MaxUsers,MaxUp,MaxDown,RatioUp,RatioDown,RatioCredit,RatioType,QuotaEnable,QuotaMax,QuotaCurrent,Groups,Privilege,LockHomeDir) values(@UserName,@Password,@Disable,@Access,@ChangePass,@PassType,@Expiration,@ExpirationType,@SKey,@RelPaths,@HomeDir,@MessageFile,@MaxUsers,@MaxUp,@MaxDown,@RatioUp,@RatioDown,@RatioCredit,@RatioType,@QuotaEnable,@QuotaMax,@QuotaCurrent,@Groups,@Privilege,@LockHomeDir)", conHost );
cmdAdd.Parameters.Add( "@UserName", UserName );
cmdAdd.Parameters.Add( "@Password", pass() );
cmdAdd.Parameters.Add( "@Disable", Disable );
cmdAdd.Parameters.Add( "@Access", Access );
cmdAdd.Parameters.Add( "@ChangePass", ChangePass );
cmdAdd.Parameters.Add( "@PassType", PassType );
cmdAdd.Parameters.Add( "@Expiration", Expiration );
cmdAdd.Parameters.Add( "@ExpirationType", ExpirationType );
cmdAdd.Parameters.Add( "@SKey", SKey );
cmdAdd.Parameters.Add( "@RelPaths", RelPaths );
cmdAdd.Parameters.Add( "@HomeDir", HomeDir );
cmdAdd.Parameters.Add( "@MessageFile", MessageFile );
cmdAdd.Parameters.Add( "@MaxUsers", MaxUsers );
cmdAdd.Parameters.Add( "@MaxUp", MaxUp );
cmdAdd.Parameters.Add( "@MaxDown", MaxDown );
cmdAdd.Parameters.Add( "@RatioUp", RatioUp );
cmdAdd.Parameters.Add( "@RatioDown", RatioDown );
cmdAdd.Parameters.Add( "@RatioCredit", RatioCredit );
cmdAdd.Parameters.Add( "@RatioType", RatioType );
cmdAdd.Parameters.Add( "@QuotaEnable", QuotaEnable );
cmdAdd.Parameters.Add( "@QuotaMax", QuotaMax );
cmdAdd.Parameters.Add( "@QuotaCurrent", QuotaCurrent );
cmdAdd.Parameters.Add( "@Groups", Groups );
cmdAdd.Parameters.Add( "@Privilege", Privilege );
cmdAdd.Parameters.Add( "@LockHomeDir", LockHomeDir );
//cmdAdd.Parameters.Add( "@", );
cmdAdd.ExecuteNonQuery();
}
public string pass()
{
//密码加密
Random rnm = new Random();
char a = (char)(rnm.Next( 97, 123 ));
char b = (char)(rnm.Next( 97, 123 ));
string password = string.Format("{0}{1}{2}", a, b, Password );
password = FormsAuthentication.HashPasswordForStoringInConfigFile( password, "md5" );
password = string.Format( "{0}{1}{2}", a, b, password.ToUpper() );
return password;
}
public bool modifypass( string oldpass, string newpass )
{
//修改密码
return true;
}
}
}
本文地址:http://com.8s8s.com/it/it42225.htm