自动生成密码并将其发送给新创建的用户电子邮件ID
问题描述:
如何编写代码以自动生成密码并将其发送给新创建的用户电子邮件ID?
how to code for auto generate password and send it to newly create user email id?
答
要生成随机密码,有两种方法:
To generate a random pasword there are two approaches:
string s = Guid.NewGuid().ToString();
string s = Membership.GeneratePassword();
后者仅适用于System.Web程序集.
要发送电子邮件,这里有一个通用的例程: ^ ]
[edit]忘记了电子邮件要求-OriginalGriff [/edit]
The latter only works with the System.Web assembly.
To email it, there is a generic routine to do that here: Sending an Email in C# with or without attachments: generic routine.[^]
[edit]Forgot the email requirement - OriginalGriff[/edit]
使用随机类生成一些随机代码作为密码
这是生成随机字符的代码
Use Random Class to generate some random code as password
This is code to generate random characters
public string fillVerCode()
{
int codeCount = 6;
string allChar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
string[] allCharArray = allChar.Split(',');
string randomCode = "";
int temp = -1;
Random rand = new Random();
for (int i = 0; i < codeCount; i++)
{
if (temp != -1)
{
rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
}
int t = rand.Next(36);
if (temp != -1 && temp == t)
{
return fillVerCode();
}
temp = t;
randomCode += allCharArray[t];
}
return randomCode;
}
然后发送邮件
检查此链接
如何通过asp.net发送电子邮件 [ ^ ]
Then to Send Mail
check this link
How to send email through asp.net[^]
这是 ^ ].请只发布一次您的问题.
This is a duplicate of this question[^]. Please post your questions once only.