473,657 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generating Random Password Code

1 New Member
I pulled this code from Vbasic.net or generating random passwords. I want to know how I can set up so that each time the page is refreshed a new password is generated without having to fill in the form boxes. Anyone lend a hand?

http://vbasic.net/detail.aspx?tid=105

Code:
<form id="form1" runat="server">
<div> Enter Required Password Length:
<asp:TextBox ID="TextBox1" runat="server" Columns="2" MaxLength="2"></asp:TextBox><br />
<asp:Label ID="Label1" runat="server"> </asp:Label><br />
<asp:Button ID="Button1" runat="server" Text="Generate Password" OnClick="Button 1_Click" />
</div>
</form> The simple method is shown below. This is how the code-behind should look:
Code:
Imports Microsoft.Visua lBasic
Imports System
Imports System.Data
Imports System.Configur ation
Imports System.Web
Imports System.Web.Secu rity
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.W ebControls.WebP arts
Imports System.Web.UI.H tmlControls

Partial Public Class _Default Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If IsPostBack Then Label1.Text = "Please enter a password length (e.g. 8)"
End If
End Sub

Public Shared Function CreateRandomPas sword(ByVal PasswordLength As Integer) As String Dim _allowedChars As String = "abcdefghijkmno pqrstuvwxyzABCD EFGHJKLMNOPQRST UVWXYZ012345678 9"
Dim randNum As New Random()
Dim chars(PasswordL ength - 1) As Char
Dim allowedCharCoun t As Integer = _allowedChars.L ength

For i As Integer = 0 To PasswordLength - 1 chars(i) = _allowedChars.C hars(CInt(Fix(( _allowedChars.L ength) * randNum.NextDou ble())))
Next i

Return New String(chars)
End Function

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As EventArgs) If TextBox1.Text <> "" Then Dim myInt As String = TextBox1.Text.T oString()
Label1.Text = "Your generated password is: " & CreateRandomPas sword(Integer.P arse(myInt))
End If
End Sub
End Class
Aug 14 '08 #1
1 2032
YarrOfDoom
1,247 Recognized Expert Top Contributor
Welcome to bytes.com Krimp.

Wouldn't reclicking the button generate a new password, it seems more handy to do that, than to refresh the page.

As for the rest, I don't think this is a VB question, and please use [code]-tags in your next questions. You might want to read the posting guidelines.
Aug 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2048
by: Peter Fox | last post by:
The recent thread in generating PINs reminded me: Suppose I want to give someone a random password or ID then this is what I do: (1) Generate a hash, eg. MD5 form something, possibly a random number. This gives a string in hex. (2) Truncate it to the required number of characters THEN (3) Substitute the characters 0,1,5,8,B,C with eg h,k,p,r,t,w,x,y.
2
1491
by: Joe | last post by:
Hi, I am building web in ASP.NET using VB.NET to code the pages. I want to generate random passwords for users. I know that password hashing is built right into the .NET Framework. I was wondering if there is any built-in support for generating random passwords in .Net. If the support is built-in, can you show me how to do it. Thanks, Joe
0
1217
by: Adam Carpenter | last post by:
Hello, I am having some problems with these functions which are to be part of the forgotten password system for a website. I am sure it is something simple but I can't see it. I would be grateful for any help anyone could offer. The plan is: The users forgets their password so they enter their email address together with responses to some security questions (currently just zip/postcode). A random password is generated and, providing...
3
1369
by: John | last post by:
Hi I need to generate a string of six random characters to act as the first password. Is there an example of how to do this somewhere? Thanks Regards
5
3925
by: k.i.n.g. | last post by:
Hi, I have a csv file which in taken as the input file for adding users in my linux mail server with the format userid,fullname,passwword,dateofbith Now I have to write a script to generate random password in the password field for each user. A simple algorithm is sufficient for passwords
2
2768
by: Simon Wittber | last post by:
I'm building a web application using sqlalchemy in my db layer. Some of the tables require single integer primary keys which might be exposed in some parts of the web interface. If users can guess the next key in a sequence, it might be possible for them to 'game' or manipulate the system in unexpected ways. I want to avoid this by generating a random key for each row ID, and have decided to use the same approach for all my single key...
14
4740
by: avanti | last post by:
Hi, I need to generate random alphanumeric password strings for the users in my application using Javascript. Are there any links that will have pointers on the same? Thanks, Avanti
3
6738
by: John | last post by:
Hi How can I generate a random password of 8 characters (digits and letters) in vb? Thanks Regards
0
25957
SammyB
by: SammyB | last post by:
These are some "random" thoughts about generating random numbers in Visual Basic. Wikipedia will give a better introduction than I, see http://en.wikipedia.org/wiki/Random_number_generator. The key point is that you need to start the random number generator with a seed. Doing it in the form load with the number of milliseconds since midnight is an easy way to start. The VB.Net version This demo project will be as simple as I can...
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.