473,465 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with Random Password Class (From VB.NET to C#.NET)

Can someone help me convert this to c#

----------------------------------------------------------------------------
-----------

Public Class ResetPassword

'Constants associated with check boxes
Private Const PASS_UPPERS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Private Const PASS_LOWERS As String = "abcdefghijklmnopqrstuvwxyz"
Private Const PASS_NUMBERS As String = "0123456789"
Private Const PASS_SPECIALS As String = "~`!@#$%^&*()_+=-{[}]|;:'<,>.?"

Public Function GeneratePassword(ByVal Uppers As Boolean, ByVal Lowers
As Boolean, ByVal Numbers As Boolean, ByVal Specials As Boolean, ByVal
passwordLength As Integer) As String

Dim strCharacters As String
Dim strNewPassword As String
Dim p As Integer

If Uppers = True Then
strCharacters = strCharacters & PASS_UPPERS
End If
If Lowers = True Then
strCharacters = strCharacters & PASS_LOWERS
End If
If Numbers = True Then
strCharacters = strCharacters & PASS_NUMBERS
End If
If Specials = True Then
strCharacters = strCharacters & PASS_SPECIALS
End If

Randomize()

For p = 0 To (passwordLength - 1)
strNewPassword = strNewPassword + Mid(strCharacters,
Len(strCharacters) * Rnd() + 1, 1)
Next

GeneratePassword = strNewPassword

End Function

End Class
Nov 15 '05 #1
4 2823
On Fri, 20 Feb 2004 15:47:13 -0500, learning_csharp wrote:
Can someone help me convert this to c#

----------------------------------------------------------------------------
-----------

Public Class ResetPassword

'Constants associated with check boxes
Private Const PASS_UPPERS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Private Const PASS_LOWERS As String = "abcdefghijklmnopqrstuvwxyz"
Private Const PASS_NUMBERS As String = "0123456789"
Private Const PASS_SPECIALS As String = "~`!@#$%^&*()_+=-{[}]|;:'<,>.?"

Public Function GeneratePassword(ByVal Uppers As Boolean, ByVal Lowers
As Boolean, ByVal Numbers As Boolean, ByVal Specials As Boolean, ByVal
passwordLength As Integer) As String

Dim strCharacters As String
Dim strNewPassword As String
Dim p As Integer

If Uppers = True Then
strCharacters = strCharacters & PASS_UPPERS
End If
If Lowers = True Then
strCharacters = strCharacters & PASS_LOWERS
End If
If Numbers = True Then
strCharacters = strCharacters & PASS_NUMBERS
End If
If Specials = True Then
strCharacters = strCharacters & PASS_SPECIALS
End If

Randomize()

For p = 0 To (passwordLength - 1)
strNewPassword = strNewPassword + Mid(strCharacters,
Len(strCharacters) * Rnd() + 1, 1)
Next

GeneratePassword = strNewPassword

End Function

End Class


Here is one possible solution:

--------
public class ResetPassword {
public static Random rnd = new Random();

private const string UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private const string LOWER = "abcdefghijklmnopqrstuvwxyz";
private const string NUMBERS = "0123456789";
private const string SYMBOLS = "~`!@#$%^&*()_+=-{[}]|;:'<,>.?";

public string GeneratePassword(bool useUpper, bool userLower,
bool userNumbers, bool useSymbols, int passwordLength) {
System.Text.StringBuilder charPool = new System.Text.StringBuilder();
System.Text.StringBuilder newPass = new System.Text.StringBuilder();

if (useUpper)
charPool.Append(UPPER);

if (userLower)
charPool.Append(LOWER);

if (userNumbers)
charPool.Append(NUMBERS);

if (useSymbols)
charPool.Append(SYMBOLS);

int max = charPool.Length;

for (int x = 0; x < passwordLength; x++) {
newPass.Append(charPool[rnd.Next(max)]);
}

return newPass.ToString();
}
-------

HTH,
Tim
--
Tim Smelser - MVP Visual C#
To email me, make the snot hot.
Nov 15 '05 #2
On Fri, 20 Feb 2004 15:47:13 -0500, learning_csharp wrote:
Can someone help me convert this to c#

----------------------------------------------------------------------------
-----------

Public Class ResetPassword

'Constants associated with check boxes
Private Const PASS_UPPERS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Private Const PASS_LOWERS As String = "abcdefghijklmnopqrstuvwxyz"
Private Const PASS_NUMBERS As String = "0123456789"
Private Const PASS_SPECIALS As String = "~`!@#$%^&*()_+=-{[}]|;:'<,>.?"

Public Function GeneratePassword(ByVal Uppers As Boolean, ByVal Lowers
As Boolean, ByVal Numbers As Boolean, ByVal Specials As Boolean, ByVal
passwordLength As Integer) As String

Dim strCharacters As String
Dim strNewPassword As String
Dim p As Integer

If Uppers = True Then
strCharacters = strCharacters & PASS_UPPERS
End If
If Lowers = True Then
strCharacters = strCharacters & PASS_LOWERS
End If
If Numbers = True Then
strCharacters = strCharacters & PASS_NUMBERS
End If
If Specials = True Then
strCharacters = strCharacters & PASS_SPECIALS
End If

Randomize()

For p = 0 To (passwordLength - 1)
strNewPassword = strNewPassword + Mid(strCharacters,
Len(strCharacters) * Rnd() + 1, 1)
Next

GeneratePassword = strNewPassword

End Function

End Class


Here is one possible solution:

--------
public class ResetPassword {
public static Random rnd = new Random();

private const string UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private const string LOWER = "abcdefghijklmnopqrstuvwxyz";
private const string NUMBERS = "0123456789";
private const string SYMBOLS = "~`!@#$%^&*()_+=-{[}]|;:'<,>.?";

public string GeneratePassword(bool useUpper, bool userLower,
bool userNumbers, bool useSymbols, int passwordLength) {
System.Text.StringBuilder charPool = new System.Text.StringBuilder();
System.Text.StringBuilder newPass = new System.Text.StringBuilder();

if (useUpper)
charPool.Append(UPPER);

if (userLower)
charPool.Append(LOWER);

if (userNumbers)
charPool.Append(NUMBERS);

if (useSymbols)
charPool.Append(SYMBOLS);

int max = charPool.Length;

for (int x = 0; x < passwordLength; x++) {
newPass.Append(charPool[rnd.Next(max)]);
}

return newPass.ToString();
}
-------

HTH,
Tim
--
Tim Smelser - MVP Visual C#
To email me, make the snot hot.
Nov 15 '05 #3
Thanks Tim, Works Great

"Tim Smelser" <t_*******@snotmail.com> wrote in message
news:gc***************************@40tude.net...
On Fri, 20 Feb 2004 15:47:13 -0500, learning_csharp wrote:
Can someone help me convert this to c#


--------------------------------------------------------------------------

--
-----------

Public Class ResetPassword

'Constants associated with check boxes
Private Const PASS_UPPERS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Private Const PASS_LOWERS As String = "abcdefghijklmnopqrstuvwxyz"
Private Const PASS_NUMBERS As String = "0123456789"
Private Const PASS_SPECIALS As String = "~`!@#$%^&*()_+=-{[}]|;:'<,>.?"
Public Function GeneratePassword(ByVal Uppers As Boolean, ByVal Lowers As Boolean, ByVal Numbers As Boolean, ByVal Specials As Boolean, ByVal
passwordLength As Integer) As String

Dim strCharacters As String
Dim strNewPassword As String
Dim p As Integer

If Uppers = True Then
strCharacters = strCharacters & PASS_UPPERS
End If
If Lowers = True Then
strCharacters = strCharacters & PASS_LOWERS
End If
If Numbers = True Then
strCharacters = strCharacters & PASS_NUMBERS
End If
If Specials = True Then
strCharacters = strCharacters & PASS_SPECIALS
End If

Randomize()

For p = 0 To (passwordLength - 1)
strNewPassword = strNewPassword + Mid(strCharacters,
Len(strCharacters) * Rnd() + 1, 1)
Next

GeneratePassword = strNewPassword

End Function

End Class


Here is one possible solution:

--------
public class ResetPassword {
public static Random rnd = new Random();

private const string UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private const string LOWER = "abcdefghijklmnopqrstuvwxyz";
private const string NUMBERS = "0123456789";
private const string SYMBOLS = "~`!@#$%^&*()_+=-{[}]|;:'<,>.?";

public string GeneratePassword(bool useUpper, bool userLower,
bool userNumbers, bool useSymbols, int passwordLength) {
System.Text.StringBuilder charPool = new System.Text.StringBuilder();
System.Text.StringBuilder newPass = new System.Text.StringBuilder();

if (useUpper)
charPool.Append(UPPER);

if (userLower)
charPool.Append(LOWER);

if (userNumbers)
charPool.Append(NUMBERS);

if (useSymbols)
charPool.Append(SYMBOLS);

int max = charPool.Length;

for (int x = 0; x < passwordLength; x++) {
newPass.Append(charPool[rnd.Next(max)]);
}

return newPass.ToString();
}
-------

HTH,
Tim
--
Tim Smelser - MVP Visual C#
To email me, make the snot hot.

Nov 15 '05 #4
Thanks Tim, Works Great

"Tim Smelser" <t_*******@snotmail.com> wrote in message
news:gc***************************@40tude.net...
On Fri, 20 Feb 2004 15:47:13 -0500, learning_csharp wrote:
Can someone help me convert this to c#


--------------------------------------------------------------------------

--
-----------

Public Class ResetPassword

'Constants associated with check boxes
Private Const PASS_UPPERS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Private Const PASS_LOWERS As String = "abcdefghijklmnopqrstuvwxyz"
Private Const PASS_NUMBERS As String = "0123456789"
Private Const PASS_SPECIALS As String = "~`!@#$%^&*()_+=-{[}]|;:'<,>.?"
Public Function GeneratePassword(ByVal Uppers As Boolean, ByVal Lowers As Boolean, ByVal Numbers As Boolean, ByVal Specials As Boolean, ByVal
passwordLength As Integer) As String

Dim strCharacters As String
Dim strNewPassword As String
Dim p As Integer

If Uppers = True Then
strCharacters = strCharacters & PASS_UPPERS
End If
If Lowers = True Then
strCharacters = strCharacters & PASS_LOWERS
End If
If Numbers = True Then
strCharacters = strCharacters & PASS_NUMBERS
End If
If Specials = True Then
strCharacters = strCharacters & PASS_SPECIALS
End If

Randomize()

For p = 0 To (passwordLength - 1)
strNewPassword = strNewPassword + Mid(strCharacters,
Len(strCharacters) * Rnd() + 1, 1)
Next

GeneratePassword = strNewPassword

End Function

End Class


Here is one possible solution:

--------
public class ResetPassword {
public static Random rnd = new Random();

private const string UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private const string LOWER = "abcdefghijklmnopqrstuvwxyz";
private const string NUMBERS = "0123456789";
private const string SYMBOLS = "~`!@#$%^&*()_+=-{[}]|;:'<,>.?";

public string GeneratePassword(bool useUpper, bool userLower,
bool userNumbers, bool useSymbols, int passwordLength) {
System.Text.StringBuilder charPool = new System.Text.StringBuilder();
System.Text.StringBuilder newPass = new System.Text.StringBuilder();

if (useUpper)
charPool.Append(UPPER);

if (userLower)
charPool.Append(LOWER);

if (userNumbers)
charPool.Append(NUMBERS);

if (useSymbols)
charPool.Append(SYMBOLS);

int max = charPool.Length;

for (int x = 0; x < passwordLength; x++) {
newPass.Append(charPool[rnd.Next(max)]);
}

return newPass.ToString();
}
-------

HTH,
Tim
--
Tim Smelser - MVP Visual C#
To email me, make the snot hot.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
16
by: BartlebyScrivener | last post by:
I am a mere hobbyist. Spent several hours trying to make a class, because I think this is an occasion where I need one. But I can't make it work. This code "works" (only because of the global c,...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
2
by: muchexie | last post by:
i have two scripts that are not running to reset a password that has been forgotten and the other to change old password. here are the scripts. change_passwd.php session_start();...
3
by: tshad | last post by:
I have a page that I am getting a username and password as a random number (2 letters, one number and 4 more letters) I have 2 functions I call: *************************************************...
8
by: sathyashrayan | last post by:
Dear group, For a log-in page I have created a mysql db and user registers with a user name and password. The password field is encrypted with $passwd = sha1($_REQUEST); I insert the...
22
by: j1mb0jay | last post by:
I have had to create a simple string encryption program for coursework, I have completed the task and now have to do a write up on how it could be improved at a later date. If you could look...
1
by: orehian | last post by:
Construct a one-time password system. · Write a server code and a client code. The server code takes as input a username and a one-time password from the client and then sends a message...
1
by: Krimp | last post by:
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.