using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Windows.Forms;

public partial class _Default : System.Web.UI.Page
{
    public static int counter = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    public static string MakePassword(string pwdchars, int pwdlen)
    {
        //判斷隨機密碼的長度
        string tmpstr = "";
        int iRandNum;
        if (pwdlen > pwdchars.Length)
        {
            return "长度过长!" + pwdchars.Length;
        }
        Random rnd = new Random();
        for (int i = 0; i < pwdlen; i++)
        {
            iRandNum = rnd.Next(pwdchars.Length);
            tmpstr += pwdchars[iRandNum];
        }
        return tmpstr;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int t1 = Convert.ToInt32(TextBox1.Text);
        if (t1 < 10 || t1 > 20 || t1 < 0)
        {
           MessageBox.Show("指定密碼失敗!");
        }//判斷指定的密碼長度是否符合
        else
        {
            string randomchars = "abcdefghijklmnopqrstuvwxyz~!@#$%^&*()_+|0123456789~!@#$%^&*()_+|ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+|";
            string password = MakePassword(randomchars, Convert.ToInt32(TextBox1.Text));
            TextBox2.Text = password;
        }//產生隨機的密碼值
    }//判斷輸入的密碼是否符合隨機產生的密碼
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (TextBox3.Text.Trim()==TextBox2.Text.Trim())
        {
           MessageBox.Show("成功!");
           Response.Write("您現在的密碼是:"+"<font color=red>"+TextBox3.Text+"</font>");
        
        }
        else
        {
            MessageBox.Show("失败!");
        }
      
    }


    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
}

HTML代码:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head >
                </td>
            </tr>
        </table>
        <br />
        <br />
        <br />
        </div>
    </form>
</body>
</html>

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhangsiyan/archive/2010/08/02/5783138.aspx

相关文章:

  • 2022-01-15
  • 2021-12-09
  • 2021-10-28
  • 2021-07-02
  • 2021-10-06
  • 2022-12-23
猜你喜欢
  • 2021-07-20
  • 2021-07-31
  • 2022-01-18
  • 2021-07-23
相关资源
相似解决方案