473,413 Members | 1,778 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,413 software developers and data experts.

Generating Random Alpha and Numeric characters

Any one have a code snippet that would show me how to:

1. Generate a 24 character
2. Random
3. Alpha Numeric data dump
4. into an array
IE.

1adftredbgRtwbertagUnrew
123456fdsgui8tghjiioojjj

I'm going to hard code the values into my app as a poormans
alternative to buying registation software for my vb.net programs.
I'll encrypt and ofusicate the code to make things fairly timely to
crack.
Nov 21 '05 #1
7 3276
i could do it with time...which I don't have atm...but I will say this. Do NOT
store any information as static strings that you don't want a user to read!!! I
wrote a security component with public/private keys to ensure that the libraries
loading this component was indeed one I wrote. I found that by opening up the
component's dll in a text editor (IE: NOTEPAD), I was able to READ the private
key in plain English!!! So remember, do NOT store any of the registration keys
inside the DLL as plain text...

Our workaround was simple, modified the text into a numeric value that
represented each letter and made it into an array. Therefore, not even a hex
editor could be used to read the information :) (By obfuscating the code, it
would only slow down the non-determined hacker...obfuscating just turns something
from English/language to jumble...which can still be followed if a hacker is
good).

Mythran
"Peter" <pe***@mclinn.com> wrote in message
news:dc**************************@posting.google.c om...
Any one have a code snippet that would show me how to:

1. Generate a 24 character
2. Random
3. Alpha Numeric data dump
4. into an array
IE.

1adftredbgRtwbertagUnrew
123456fdsgui8tghjiioojjj

I'm going to hard code the values into my app as a poormans
alternative to buying registation software for my vb.net programs.
I'll encrypt and ofusicate the code to make things fairly timely to
crack.

Nov 21 '05 #2
Could someone post some code? Even a small hint in the right
direction would be appreciated.
Nov 21 '05 #3
Dim rd As New Random(Convert.ToInt32(DateTime.Now.Ticks Mod
Integer.MaxValue))

Dim ch() As Char = {"A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c, "H"c, "I"c,
"J"c, "K"c, "L"c, "M"c, "O"c, "P"c, "Q"c, "R"c, "S"c, "T"c, "U"c, "V"c,
"W"c, "X"c, "Y"c, "Z"c, "a"c, "b"c, "c"c, "d"c, "e"c, "f"c, "g"c, "h"c,
"i"c, "j"c, "k"c, "l"c, "m"c, "o"c, "p"c, "q"c, "r"c, "s"c, "t"c, "u"c,
"v"c, "w"c, "x"c, "y"c, "z"c, "0"c, "1"c, "2"c, "3"c, "4"c, "5"c, "6"c,
"7"c, "8"c, "9"c}

Private Function CreateRandomString() As String

Dim i As Integer
Dim number As Integer = rd.Next(4, 12)
Dim str As New System.Text.StringBuilder

For i = 0 To number
str.Append(ch(rd.Next(0, ch.Length)))
Next

Return str.ToString

End Function

"Peter" <pe***@mclinn.com> wrote in message
news:dc**************************@posting.google.c om...
Could someone post some code? Even a small hint in the right
direction would be appreciated.

Nov 21 '05 #4
Thank you.

If you don't mind me asking...:

The lower case c after the "A", "B"'s... what does it stand for.... I
have never seen this type of declaring.

I'll read up on the string builder class. Thank you again.

-Peter
Dim rd As New Random(Convert.ToInt32(DateTime.Now.Ticks Mod
Integer.MaxValue))

Dim ch() As Char = {"A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c, "H"c, "I"c,
"J"c, "K"c, "L"c, "M"c, "O"c, "P"c, "Q"c, "R"c, "S"c, "T"c, "U"c, "V"c,
"W"c, "X"c, "Y"c, "Z"c, "a"c, "b"c, "c"c, "d"c, "e"c, "f"c, "g"c, "h"c,
"i"c, "j"c, "k"c, "l"c, "m"c, "o"c, "p"c, "q"c, "r"c, "s"c, "t"c, "u"c,
"v"c, "w"c, "x"c, "y"c, "z"c, "0"c, "1"c, "2"c, "3"c, "4"c, "5"c, "6"c,
"7"c, "8"c, "9"c}

Private Function CreateRandomString() As String

Dim i As Integer
Dim number As Integer = rd.Next(4, 12)
Dim str As New System.Text.StringBuilder

For i = 0 To number
str.Append(ch(rd.Next(0, ch.Length)))
Next

Return str.ToString

End Function

Nov 21 '05 #5
It means that it's a Char and not a string. If you omit it, you'll get an
error.
"Peter" <pe***@mclinn.com> wrote in message
news:dc**************************@posting.google.c om...
Thank you.

If you don't mind me asking...:

The lower case c after the "A", "B"'s... what does it stand for.... I
have never seen this type of declaring.

I'll read up on the string builder class. Thank you again.

-Peter
Dim rd As New Random(Convert.ToInt32(DateTime.Now.Ticks Mod
Integer.MaxValue))

Dim ch() As Char = {"A"c, "B"c, "C"c, "D"c, "E"c, "F"c, "G"c, "H"c, "I"c,
"J"c, "K"c, "L"c, "M"c, "O"c, "P"c, "Q"c, "R"c, "S"c, "T"c, "U"c, "V"c,
"W"c, "X"c, "Y"c, "Z"c, "a"c, "b"c, "c"c, "d"c, "e"c, "f"c, "g"c, "h"c,
"i"c, "j"c, "k"c, "l"c, "m"c, "o"c, "p"c, "q"c, "r"c, "s"c, "t"c, "u"c,
"v"c, "w"c, "x"c, "y"c, "z"c, "0"c, "1"c, "2"c, "3"c, "4"c, "5"c, "6"c,
"7"c, "8"c, "9"c}

Private Function CreateRandomString() As String

Dim i As Integer
Dim number As Integer = rd.Next(4, 12)
Dim str As New System.Text.StringBuilder

For i = 0 To number
str.Append(ch(rd.Next(0, ch.Length)))
Next

Return str.ToString

End Function

Nov 21 '05 #6
In article <dc**************************@posting.google.com >, Peter wrote:
Could someone post some code? Even a small hint in the right
direction would be appreciated.


Option Strict On
Option Explicit On

Imports System.Text

Module Module1

Sub Main()
Dim bytes(23) As Byte
Dim rnd As New Random

For i As Integer = 0 To 23
Select Case rnd.Next(0, 3)
Case 0
bytes(i) = CByte(rnd.Next(48, 58))
Case 1
bytes(i) = CByte(rnd.Next(65, 91))
Case 2
bytes(i) = CByte(rnd.Next(97, 123))
End Select
Next

Console.WriteLine(Encoding.ASCII.GetString(bytes))
End Sub

End Module

Here you go...
--
Tom Shelton [MVP]
Nov 21 '05 #7
In article <dc**************************@posting.google.com >, Peter wrote:
Any one have a code snippet that would show me how to:

1. Generate a 24 character
2. Random
3. Alpha Numeric data dump
4. into an array
IE.

1adftredbgRtwbertagUnrew
123456fdsgui8tghjiioojjj

I'm going to hard code the values into my app as a poormans
alternative to buying registation software for my vb.net programs.
I'll encrypt and ofusicate the code to make things fairly timely to
crack.


Peter,

I would suggest, if you really need a unique id - that you use a GUID
for this... It is a few more then 24 characters, but it is guarenteed*
to be unique.

Dim id As String = Guid.NewGuid().ToString("N")
Console.WriteLine(id)

In this format you get a 32 characther string.
--
Tom Shelton [MVP]
Nov 21 '05 #8

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

Similar topics

7
by: eric.gagnon | last post by:
In a program randomly generating 10 000 000 alphanumeric codes of 16 characters in length (Ex.: "ZAZAZAZAZAZAZ156"), what would be an efficient way to ensure that I do not generate duplicates? ...
3
by: success_ny | last post by:
Does anyone have a code snippet to compare those values so I can sort the array of alpha-numeric values that include both characters and integers in it? I.e., if we have values like 4236 and...
6
by: Mark C | last post by:
All, Is there such a function that can strip all non alpha ( not between a-z) characters from a string? I have a function that I currently use that will strip one character at a time from a...
14
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
5
by: vrkamalakar | last post by:
Hi, Can I get a piece of code which can generate a 10 - 15 digit/character of uinque Random Number. The generated random number can contain both characters and digits. Regards, Kamalakar.
8
by: .Net Sports | last post by:
I am checking for text input on a form validation in javascript that required at least one numeric character along with any number of alpha characters for a given input text box. The below is a var...
5
lotus18
by: lotus18 | last post by:
Hello World! I have a sample code here written in vb .net that restricts the textbox to accept only alpha, alphanumeric or numeric characters. Public Enum MyOption Alpha = 1 ...
1
by: pranaysharmadelhi | last post by:
I want to generate a regular expression for password check.(ASP.Net) But javascript is what it really is. I would like to enforce Minimum 6 alphanumeric characters with minimum 1 numeric(0-9) and 1...
9
xaxis
by: xaxis | last post by:
Context: I'm working on a function that generates domain names. For instance, if I want to generate every possible domain name with 3 alpha characters, I've been doing something like this: ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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: 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...

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.