473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 2820
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.