Vs.net2003+Sql2003+Serv-u实现在线注册FTP功能——程序设计

这里主要说名如何通过程序来为SERV-U创建客户帐户。

前提条件。

1。你的SERV-U能够访问。

2。你要动态创建的帐号。你已经为它设计了一个权限组。


这里我设计了一个用户组USER、它的权限是只能上传,列出目录。&继承。

这个程序只是简单的添加一个用户。然后通过MD5加密算法加密用户密码。并将其保存在SQL服务器中。

代码如下:

  1using System;
  2using System.Collections;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Data.SqlClient;
  6using System.Drawing;
  7using System.Web;
  8using System.Web.SessionState;
  9using System.Web.UI;
 10using System.Web.UI.WebControls;
 11using System.Web.UI.HtmlControls;
 12using System.Security.Cryptography;
 13
 14namespace webopenftpuser
 15{
 16 /// <summary>
 17 /// WebForm1 的摘要说明。
 18 /// </summary>

 19 public class WebForm1 : System.Web.UI.Page
 20 {
 21  protected System.Web.UI.WebControls.TextBox TextBox1;
 22  protected System.Web.UI.WebControls.Button Button1;
 23  protected System.Web.UI.WebControls.TextBox TextBox2;
 24  protected System.Web.UI.WebControls.Literal Literal2;
 25 
 26  private void Page_Load(object sender, System.EventArgs e)
 27  {
 28   // 在此处放置用户代码以初始化页面
 29  }

 30
 31  Web 窗体设计器生成的代码
 52
 53  private void Button1_Click(object sender, System.EventArgs e)
 54  {
 55   this.Literal2.Text=GotoMd5code(this.TextBox1.Text).ToUpper();
 56   Login();
 57  }

 58  private string GotoMd5code(string temp)
 59  {
 60   MD5 md5=new MD5CryptoServiceProvider();
 61   byte[] data=System.Text.Encoding.Default.GetBytes(temp);
 62   byte[] md5data=md5.ComputeHash(data);
 63   string str="";
 64   for(int i=0;i<md5data.Length;i++)
 65   {
 66    str+=md5data[i].ToString("x").PadLeft(2,'0');
 67   }

 68   return str;
 69  }

 70  private void Login()
 71  {
 72   /*
 73    * ftpUserName
 74    * ftpPassword
 75    * ftpPasswordType
 76    * dirHome
 77    * dirHomeLock
 78    * groups
 79    */

 80   string[] strcol=new string[6];
 81   string[] strval=new string[6];
 82
 83   strcol[0]="ftpUserName";
 84   strval[0]=this.TextBox1.Text;
 85
 86   strcol[1]="ftpPassword";
 87   strval[1]="pn"+GotoMd5code("pn"+this.TextBox2.Text);
 88
 89   strcol[2]="ftpPasswordType";
 90   strval[2]="0";
 91
 92   strcol[3]="dirHome";
 93   strval[3]=@"F:\BitComet";
 94
 95   strcol[4]="dirHomeLock";
 96   strval[4]=true.ToString();
 97
 98   strcol[5]="groups";
 99   strval[5]="User";
100            
101   ConnSql.Conndb OpenSql=new ConnSql.Conndb();
102   SqlConnection SqlConn=OpenSql.ConnSql();
103   SqlConn.Open();
104
105   string SqlStr="SELECT * FROM ftp_users where id is NULL";
106   int info=OpenSql.AddDate(SqlStr,SqlConn,"ftp_users",strcol,strval);
107   
108  }

109 }

110}

所用到的数据表、

    * ftpUserName
    * ftpPassword
    * ftpPasswordType
    * dirHome
    * dirHomeLock
    * groups

posted @ 2006-01-11 14:42  2008.5.12  阅读(950)  评论(2编辑  收藏  举报