Click here to Skip to main content
12,447,786 members (63,930 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
how to code for auto generate password and send it to newly create user email id?
Posted 28-Oct-11 23:39pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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]
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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 asp.net[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

This is a duplicate of this question[^]. Please post your questions once only.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 29 Oct 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100