自动生成密码并将其发送给新创建的用户电子邮件ID [英] auto generate password and send it to newly create user email id

查看:126
本文介绍了自动生成密码并将其发送给新创建的用户电子邮件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程序集.

要发送电子邮件,这里有一个通用的例程:

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.


这篇关于自动生成密码并将其发送给新创建的用户电子邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆