第一步:首先新建一个页面register页面,在该页面的前台添加上用户名、密码、邮箱地址和三个文本框以及注册按钮。
第二步:在register页面的register.aspx.cs页面加上以下代码:
public void sendMail(string email, string activeCode,int number)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("q******09@126.com");////填写一个126的邮箱
msg.To.Add(email);
msg.Subject = "请激活注册";
StringBuilder contentBuilder = new StringBuilder();
contentBuilder.Append("请单击以下连接完成激活!");
contentBuilder.Append("<a href='http://localhost:8899/CheckActiveCode.aspx?activecode="+activeCode+"&id="+number+"'>激活</a>");
msg.Body = contentBuilder.ToString();
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "smtp.126.com";//发件方服务器地址
client.Port = 25;//发件方端口
NetworkCredential credetial = new NetworkCredential();
credetial.UserName = "qzc900809";
credetial.Password = "900809";
client.Credentials = credetial;//把证书交给代理。
client.Send(msg);/////发送邮件
}
第三步:在注册按钮的单击事件中加上以下代码:
protected void Button1_Click(object sender, EventArgs e)
{
string userName = this.TextBox1.Text;
string password = this.TextBox2.Text;
string email = this.TextBox3.Text;
string activeCode = Guid.NewGuid().ToString().Substring(0, 8);//生成激活码
string conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;//在web.Confing中设置连接数据库字符串
int number;
using (SqlConnection con = new SqlConnection(conStr))
{
string sql = "insert into email (UserName,Password,Email,Active,ActiveCode) values(@username,@password,@email,@active,@activecode)";
SqlParameter[] prams = new SqlParameter[] {
new SqlParameter("@username",userName),
new SqlParameter("@password",password),
new SqlParameter("@email",email),
new SqlParameter("@active",false),/////////这个是查看是否激活
new SqlParameter("@activecode",activeCode)///////激活码
};
using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
cmd.Parameters.AddRange(prams);
number = cmd.ExecuteNonQuery();
}
}
if (number > 0)
{
sendMail(email, activeCode);
//sendMail(string email,string activeCode,int id);//给注册用户发邮件
Response.Redirect("regionMessage.aspx");///////这个可有可无,只是一个提示成功的页面
}
else
{
Response.Write("注册失败,请重新注册!");
}
}
第四步:再重新新建一个CheckActiveCode.aspx页面,然后再该页面(CheckActiveCode.aspx.cs)的Page_Load中
加上以下代码:
//1取出参数id
int id = Convert.ToInt32(Request["zcid"]);
string activeCode = Request["activecode"].ToString();
//2判断id为id的记录是否存在。
//连接数据库
string conStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
int number;
using (SqlConnection con = new SqlConnection(conStr))
{
string sql = "select count(*) from Registor where
zcid=@id";
using (SqlCommand cmd=new SqlCommand(sql,con))
{
con.Open();
cmd.Parameters.AddWithValue("@id",id);
number=Convert.ToInt32(cmd.ExecuteScalar());
}
}
if (number > 0)
{
//如果该用户存在取出其ActiveCode字段进行比较。如果一样。把Ative字段修改为true
&nbs
有时候会遇到这样的需求,不希望命令行的某些参数被ps出来,比如命令行参数里可能存在一些用户名和密码之类的东西,在linux下如果你想隐藏这些东西的话,可以直接将argv中的这些参数变成其他东西,比如xxxxx,下面是一个hideArg函数示例
void hideArg(int argc, char** argv, const char* arg)
{
for (int i = 1; i < argc; i++)
{
if (strcmp(argv[i], arg) || i == (argc - 1))
{
continue;
}
i++;
int j = strlen(argv[i]);
for (j = j - 1; j >= 0; j--)
{
argv[i][j] = 'x';
}
}
}
// This is a part of the Active Template Library.
// Copyright (C) 1996-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Active Template Library Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Active Template Library product.
#ifndef __ATLBASE_H__
#error atlimpl.cpp requires atlbase.h to be included first
#endif
/////////////////////////////////////////////////////////////////////////////
// Minimize CRT
// Specify DllMain as EntryPoint
// Turn off exception handling
// Define _ATL_MIN_CRT
#ifdef _ATL_MIN_CRT
/////////////////////////////////////////////////////////////////////////////
// Startup Code
#if defined(_WINDLL) || defined(_USRDLL)
// Declare DllMain
extern "C" BOOL WINAPI DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved);
extern "C" BOOL WINAPI _DllMainCRTStartup(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved)
{
return DllMain(hDllHandle, dwReason, lpReserved);
}
#else
// wWinMain is not defined in winbase.h.
extern "C" int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd);
#define SPACECHAR _T(' ')
#define DQUOTECHAR _T('\"')
#ifdef _UNICODE
extern "C" void wWinMainCRTStartup()
#else // _UNICODE
extern "C" void WinMainCRTStartup()
#endif // _UNICODE
{
LPTSTR lpszCommandLine = ::GetCommandLine();
if(lpszCommandLine == NULL)
::ExitProcess((UINT)-1);
// Skip past program name (first token in command line).
// Check for and handle quoted program name.
if(*lpszCommandLine == DQUOTECHAR)
{
// Scan, and skip over, subsequent characters until
// another double-quote or a null is encountered.
do
{
lpszCommandLine = ::CharNext(lpszCommandLine);
}
while((*lpszCommandLine != DQUOTECHAR) && (*lpszCommandLine != _T('\0')));
// If we stopped on a double-quote (usual case), skip over it.
if(*lpszCommandLine == DQUOTECHAR)
lpszCommandLine = ::CharNext(lpszCommandLine);
}
else
{
while(*lpszCommandLine > SPACECHAR)
lpszCommandLine = ::CharNext(lpszCommandLine);
}
// Skip past any white space preceeding the second token.
while(*lpszCommandLine && (*lpszCommandLine <= SPACECHAR))
lpszCommandLine = ::CharNext(lpszCommandLine);
STARTUPINFO StartupInfo;
StartupInfo.dwFlags = 0;
::GetStartupInfo(&StartupInfo);
int nRet = _tWinMain(::GetModuleHandle(NULL), NULL, lpszCommandLine,
(StartupInfo.dwFlags & STARTF_USESHOWWINDOW) ?
StartupInfo.wShowWindow : SW_SHOWDEFAULT);
::ExitProcess((UINT)nRet);
}
#endif // defined(_WINDLL) | defined(_USRDLL)
/////////////////////////////////////////////////////////////////////////////
// Heap Allocation
#ifndef _DEBUG
#ifndef _MERGE_PROXYSTUB
//rpcproxy.h does the same thing as this
int __cdecl _purecall()
{
DebugBreak();
return 0;
}
#endif
#if !defined(_M_ALPHA) && !defined(_M_PPC)
//RISC always initializes floating point and always defines _fltused
extern "C" const int _fltused = 0;
#endif
static const int nExtraAlloc = 8;
static const int nOffsetBlock = nExtraAlloc/sizeof(HANDLE);
void* __cdecl malloc(size_t n)
{
void* pv = NULL;
#ifndef _ATL_NO_MP_HEAP
if (_Module.m_phHeaps == NULL)
#endif
{
pv = (HANDLE*) HeapAlloc(_Module.m_hHeap, 0, n);
}
#ifndef _ATL_NO_MP_HEAP
else
{
// overallocate to remember the heap handle
int nHeap = _Module.m_nHeap++;
HANDLE hHeap = _Module.m_phHeaps[nHeap & _Module.m_dwHeaps];
HANDLE* pBlock = (HANDLE*) HeapAlloc(hHeap, 0, n + nExtraAlloc);
if (pBlock != NULL)
{
*pBlock = hHeap;
pv = (void*)(pBlock + nOffsetBlock);
}
else
pv = NULL;
}
#endif
return pv;
}
void* __cdecl calloc(size_t n, size_t s)
{
return malloc(n*s);
}
void* __cdecl realloc(void* p, size_t n)
{
if (p == NULL)
return malloc(n);
#ifndef _ATL_NO_MP_HEAP
if (_Module.m_phHeaps == NULL)
#endif
return HeapReAlloc(_Module.m_hHeap, 0, p, n);
#ifndef _ATL_NO_MP_HEAP
else
{
HANDLE* pHeap = ((HANDLE*)p)-nOffsetBlock;
pHeap = (HANDLE*) HeapReAlloc(*pHeap, 0, pHeap, n + nExtraAlloc);
return (pHeap != NULL) ? pHeap + nOffsetBlock : NULL;
}
#endif
}
void __cdecl free(void* p)
{
if (p == NULL)
return;
#ifndef _ATL_NO_MP_HEAP
if (_Module.m_phHeaps == NULL)
#endif
HeapFree(_Module.m_hHeap, 0, p);
#ifndef _ATL_NO_MP_HEAP
else
{
HANDLE* pHeap = ((HANDLE*)p)-nOffsetBlock;
HeapFree(*pHeap, 0, pHeap);
}
#endif
}
void* __cdecl operator new(size_t n)
{
return malloc(n);
}
void __cdecl operator delete(void* p)
{
free(p);
}
#endif //_DEBUG
#endif //_ATL_MIN_CRT