Hi friends here I have written the code to generate the auto generated password
open the visual studio
select the new website
After that copy and paste the following code in aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form2" runat="server"> <div> <asp:Button ID="btnpassword" runat="server" onclick="btnpassword_Click" Text="Generate Password" /> </div> <div> <asp:GridView ID="gvid" runat="server"> </asp:GridView> </div> </form> </body> </html> |
After that open the aspx.cs file before copy and paste the code declare the two variables globally
string strPassword = string.Empty; Random objRandom = new Random(); After that write the following code in button click protected void btnpassword_Click(object sender, EventArgs e) { string password = generatePassword(6); gvid.DataSource = password; gvid.DataBind(); } After that write the following code for generate passowrd private string generatePassword(int length) { int randomNumber; int i = 1; string strTemp; while (i <= length) { randomNumber = objRandom.Next(1, 30); strTemp = (string)Microsoft.VisualBasic.Interaction.Choose(randomNumber, "B", "!", "D", "2", "F", "3", "$", "4", "a", "5", "j", "6", "K", "7", "L", "8", "m", "9", "N", "p", "@", "X", "Y", "#", "G", "H", "%", "R", "w"); strPassword += strTemp; i++; } return strPassword; } |
And you have to give the Microsoft. Visual basic reference to that particular project.
After that press F5 you will see the auto generated password for every button click
I think this code will help you.
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
12 comments :
Hello Suresh,
I tried with this code in my project and i got errors on this
1)objrandom.next are you missing assembly refrence
i already add visual basic what you said i did that
hi suresh i got an error in this code Error 1 The type or namespace name 'Interaction' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
hi suresh i got an error in this code Error 1 The type or namespace name 'Interaction' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
@ All You need to add a reference as suresh already mentioned.right click on ur website>add reference>under .net column select Microsoft. Visual basic.
Thats it.
hai sir , this code working well when we open website.. bt if we open project means its displayed the parse error like
"<%@ Application Codebehind="Global.asax.cs" Inherits="Generate_password.Global" Language="C#" %>"
how to clear it?? help me
Hi everyone,not to declare globally.
string strPassword = string.Empty;
Random objRandom = new Random();
Modify the generatePassword code like these it works.
private string generatePassword(int length)
{
string strPassword = string.Empty;
Random objRandom = new Random();
int randomNumber;
int i = 1;
string strTemp;
while (i <= length)
{
randomNumber = objRandom.Next(1, 30);
strTemp = (string)Microsoft.VisualBasic.Interaction.Choose(randomNumber, "B", "!", "D", "2", "F", "3", "$", "4", "a", "5", "j", "6", "K", "7", "L", "8", "m", "9", "N", "p", "@", "X", "Y", "#", "G", "H", "%", "R", "w");
strPassword += strTemp;
i++;
}
return strPassword;
}
From Sunny Vishwakarma
sunnyvishwakarma940@gmail.com
Thanks, you help me solve the password problem.
venkatesh maddireddy: For resoving the error you faced, you need to add Microsoft.VisualBasic dll in your references.
Its Working Dude....Thank you So Much........
its working very Easily......
Awesome.......
Thanks Again....
thank you ..Its working.
hai suresh . its working :) thanks
Note: Only a member of this blog may post a comment.