Click here to Skip to main content
15,745,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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();
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]
Share this answer
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;

Then to Send Mail
check this link

How to send email through[^]
Share this answer
This is a duplicate of this question[^]. Please post your questions once only.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900