詳情請參考: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;
}
}
}