KennethTejadaKGJL
Meta Breaker
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
400 XP
In this tutorial we will create a Simple Random Password Generator using C#. C# is a general-purpose, object-oriented programming language. C# automatically manages inaccessible object memory using a garbage collector, which eliminates developer concerns and memory leaks. It has a designed for improving productivity in the development of Web applications. It has a friendly environment for all new developers. So let's do the coding.
Getting Started
First you will have to download & install the Visual Studio. Visual Studios is an open source development feel free to create any application that you want.
Here's the link for the Visual Studio https://www.visualstudio.com/
Application Design
We will now create the design for the application, first locate the designer file called form1.Designer.cs, this is the default name when you create a new windows form. Then write these codes inside your designer file.
or also you create the layout by dragging the designating tools to the forms.
Creating the Script
This code contains the function of the application. This will code will try to trigger the event that will generate a random character when the button is clicked. To do that locate the csharp script, In my case the default script will be called Form1.cs. Then write these block of codes inside the Class of the form called Form1.
Try to run the application and see if it works.
There you go we successfully create a Simple Random Number Generator using C#. I hope that this tutorial help you understand on how to develop an application using C#. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!
Download
Getting Started
First you will have to download & install the Visual Studio. Visual Studios is an open source development feel free to create any application that you want.
Here's the link for the Visual Studio https://www.visualstudio.com/
Application Design
We will now create the design for the application, first locate the designer file called form1.Designer.cs, this is the default name when you create a new windows form. Then write these codes inside your designer file.
- namespace
Simple_Random_Password_Generator
- {
- partial
class
Form1
- {
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private
System.ComponentModel
.
IContainer
components =
null
;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected
override
void
Dispose(
bool
disposing)
- {
- if
(
disposing &&
(
components !=
null
)
)
- {
- components.
Dispose
(
)
;
- }
- base
.
Dispose
(
disposing)
;
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private
void
InitializeComponent(
)
- {
- this
.
btn_generate
=
new
System
.
Windows
.
Forms
.
Button
(
)
;
- this
.
lbl_password
=
new
System
.
Windows
.
Forms
.
Label
(
)
;
- this
.
SuspendLayout
(
)
;
- //
- // btn_generate
- //
- this
.
btn_generate
.
BackColor
=
System.Drawing
.
Color
.
White
;
- this
.
btn_generate
.
Font
=
new
System.Drawing
.
Font
(
"Arial"
, 11F, System.Drawing
.
FontStyle
.
Italic
, System.Drawing
.
GraphicsUnit
.
Point
, (
(
byte
)
(
0
)
)
)
;
- this
.
btn_generate
.
Location
=
new
System.Drawing
.
Point
(
146
, 261
)
;
- this
.
btn_generate
.
Name
=
"btn_generate"
;
- this
.
btn_generate
.
Size
=
new
System.Drawing
.
Size
(
225
, 45
)
;
- this
.
btn_generate
.
TabIndex
=
0
;
- this
.
btn_generate
.
Text
=
"Generate"
;
- this
.
btn_generate
.
UseVisualStyleBackColor
=
false
;
- this
.
btn_generate
.
Click
+=
new
System
.
EventHandler
(
this
.
Generate
)
;
- //
- // lbl_password
- //
- this
.
lbl_password
.
AutoSize
=
true
;
- this
.
lbl_password
.
Font
=
new
System.Drawing
.
Font
(
"Arial"
, 20F, System.Drawing
.
FontStyle
.
Regular
, System.Drawing
.
GraphicsUnit
.
Point
, (
(
byte
)
(
0
)
)
)
;
- this
.
lbl_password
.
ForeColor
=
System.Drawing
.
Color
.
Lime
;
- this
.
lbl_password
.
Location
=
new
System.Drawing
.
Point
(
126
, 94
)
;
- this
.
lbl_password
.
Name
=
"lbl_password"
;
- this
.
lbl_password
.
Size
=
new
System.Drawing
.
Size
(
254
, 45
)
;
- this
.
lbl_password
.
TabIndex
=
1
;
- this
.
lbl_password
.
Text
=
"PASSWORD"
;
- this
.
lbl_password
.
TextAlign
=
System.Drawing
.
ContentAlignment
.
MiddleCenter
;
- //
- // Form1
- //
- this
.
AutoScaleDimensions
=
new
System.Drawing
.
SizeF
(
9F, 20F)
;
- this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
- this
.
BackColor
=
System.Drawing
.
SystemColors
.
ActiveCaptionText
;
- this
.
ClientSize
=
new
System.Drawing
.
Size
(
539
, 358
)
;
- this
.
Controls
.
Add
(
this
.
lbl_password
)
;
- this
.
Controls
.
Add
(
this
.
btn_generate
)
;
- this
.
Name
=
"Form1"
;
- this
.
ShowIcon
=
false
;
- this
.
ShowInTaskbar
=
false
;
- this
.
StartPosition
=
System
.
Windows
.
Forms
.
FormStartPosition
.
CenterScreen
;
- this
.
Text
=
"Simple Password Generator"
;
- this
.
ResumeLayout
(
false
)
;
- this
.
PerformLayout
(
)
;
- }
- #endregion
- private
System
.
Windows
.
Forms
.
Button
btn_generate;
- private
System
.
Windows
.
Forms
.
Label
lbl_password;
- }
- }
or also you create the layout by dragging the designating tools to the forms.
Creating the Script
This code contains the function of the application. This will code will try to trigger the event that will generate a random character when the button is clicked. To do that locate the csharp script, In my case the default script will be called Form1.cs. Then write these block of codes inside the Class of the form called Form1.
- private
void
Generate(
object
sender, EventArgs e)
- {
- string
characters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
;
- StringBuilder stringBuilder =
new
StringBuilder(
)
;
- Random random =
new
Random(
)
;
- int
passwordLength =
random.
Next
(
8
, 13
)
;
- while
(
passwordLength--
>
0
)
{
- stringBuilder.
Append
(
characters[
random.
Next
(
characters.
Length
)
]
)
;
- }
- lbl_password.
Text
=
stringBuilder.
ToString
(
)
;
- }
Try to run the application and see if it works.
There you go we successfully create a Simple Random Number Generator using C#. I hope that this tutorial help you understand on how to develop an application using C#. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!
Download
You must upgrade your account or reply in the thread to view hidden text.