0% found this document useful (0 votes)
66 views17 pages

Generating Password and Otp in Java

This document provides an overview of generating passwords and one-time passwords (OTPs) in Java. It discusses using the Eclipse integrated development environment to generate random passwords of a specified length and OTPs of a specified number of digits. It also covers configuring Eclipse, the advantages of using an IDE, and the basics of the Java programming language.

Uploaded by

chamanthi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views17 pages

Generating Password and Otp in Java

This document provides an overview of generating passwords and one-time passwords (OTPs) in Java. It discusses using the Eclipse integrated development environment to generate random passwords of a specified length and OTPs of a specified number of digits. It also covers configuring Eclipse, the advantages of using an IDE, and the basics of the Java programming language.

Uploaded by

chamanthi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

1

GENERATING PASSWORD AND OTP IN JAVA


A case study report submitted in partial fulfillment of the subject

INTEGRATED DEVELOPMENT ENVIRONMENT


IN
B.TECH . IV YEAR VII SEMISTER
OF
COMPUTER SCIENCE AND ENGINEERING
Submitted by
A.Chamanthi (121710305004)
B.Pavani (121710305008)
K.Pavan Krishna Chand (121710305027)
M.Vishnu Vipul (121710305057)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


GITAM INSTITUTE OF TECHNOLOGY
GITAM
(Deemed to be University)
VISAKHAPATNAM
DECEMBER 2020
2

INDEX
3

1. INTRODUCTION

1.1. INTEGRATED DEVELOPMENT ENVIRONMENT


An IDE, or Integrated Development Environment, enables programmers to consolidate the
different aspects of writing a computer program.

IDEs increase programmer productivity by combining common activities of writing software


into a single application: editing source code, building executables, and debugging.

1.2. ADVANTAGES OF IDE:


 Using IDE will cost you less time and effort .
 Navigation is made easier.
 Auto completion- one of the best features , you don’t have to remember all.
 4.Refactoring
 Error debugging is easy , you can easily navigate to Error line.
 6.All files can be viewed and managed at same screen.
 7.Organizing you imports.
 8.Downloading requires packages at ease.

2. ECLIPSE

The Eclipse IDE has a very long development history. In November 2001, IBM created
the Eclipse Project to implement a Java-based IDE that supports development of embedded
Java applications. The initial version of Eclipse derives from Visual Age - a multi-
programming language IDE from IBM.
In January 2004, the Eclipse Foundation was established as an independent not-for-profit
corporation to transparently develop the Eclipse Project as an open and vendor-neutral
product.
Originally created for developing a Java IDE, the Eclipse Foundation is now developing a
wide range of development tools that support many programming languages: C/C++, PHP,
Javascript, Python, Rust…However Eclipse is best known as the most widely used IDE for
Java development.
Because the Eclipse Foundation releases many packages for different programming
languages and different domains, in this course the name Eclipse or Eclipse IDE refers to the
package Eclipse IDE for Java EE Developers. And as Java programmer, you use this
package most of the time.
For me, I started using Eclipse in 2004 - Eclipse 3.0 with JDK 1.4.
4

Eclipse is free and open-source, which means you can use it at no cost and access its source
code if needed. Today, Eclipse is the most widely used IDE for developing Java applications,
with millions of programmers using every day. The homepage of Eclipse is eclipse.org.
 

2.1. PROGRAMMING LANGUAGE IS USED TO MAKE


ECLIPSE

Eclipse IDE is written mostly in Java and some native parts are written in C/C++. Eclipse can
run on major operating systems like Windows, Mac and Linux. So if you are using Eclipse
IDE, you are actually running a Java application!
   

2.2. VERSIONS OF ECLIPSE

Eclipse has a long history of development so it has been evolving over many versions.
Eclipse uses interesting naming for its versions, mostly based on astronomy scheme: Juno,
Kepler, Luna, Mars, Neon, Oxygen, Photon…and the latest version uses different naming
scheme, i.e. month-year format: Eclipse 2018-09.
Though evolving over many versions, the key concepts, structure and working of the IDE
remain unchanged. Mostly new features and improvements were added.

2.3. ADVANTAGES
1. It is free and open source.
2. Industrial level of development
3. It supports many other languages other than JAVA.
4. Framework integration like Junit and TestNG and other plugins can be done
easily.
5. Since Eclipse tools are open source, they are quickly updated with the latest
technology that can be integrated into existing code.

2.4. DOWNLOADING AND INSTALLATION OF ECLIPSE


5

2.4.1. DOWNLOADING
You can download eclipse from http://www.eclipse.org/downloads/. The download page lists
a number of flavors of eclipse.

The capabilities of each packaging of eclipse are different. Java developers typically use
Eclipse Classic or Eclipse IDE for developing Java applications.
The drop down box in the right corner of the download page allows you to set the operating
system on which eclipse is to be installed. You can choose between Windows, Linux and
Mac. Eclipse is packaged as a zip file.

2.4.2. INSTALLING ECLIPSE


To install on windows, you need a tool that can extract the contents of a zip file. For
example you can use −

 7-zip
 PeaZip
 IZArc
Using any one of these tools, extract the contents of the eclipse zip file to any folder of your
choice.
6

2.5. LAUNCHING ECLIPSE


On the windows platform, if you extracted the contents of the zip file to c:\, then you can
start eclipse by using c:\eclipse\eclipse.exe
When eclipse starts up for the first time it prompts you for the location of the workspace
folder. All your data will be stored in the workspace folder. You can accept the default or
choose a new location.

If you select "Use this as the default and do not ask again", this dialog box will not come up
again. You can change this preference using the Workspaces Preference Page.
7

2.6. PARTS OF AN ECLIPSE WINDOW


The major visible parts of an eclipse window are −

 Views
 Editors (all appear in one editor area)
 Menu Bar
 Toolbar
An eclipse perspective is the name given to an initial collection and arrangement of views
and an editor area. The default perspective is called java. An eclipse window can have
multiple perspectives open in it but only one perspective can be active at any point of time.
A user can switch between open perspectives or open a new perspective. A perspective
controls what appears in some menus and tool bars.

A perspective has only one editor area in which multiple editors can be open. The editor area
is usually surrounded by multiple views. In general, editors are used to edit the project data
and views are used to view the project metadata. For example the package explorer shows
the java files in the project and the java editor is used to edit a java file.
8

The eclipse window can contain multiple editors and views but only one of them is active at
any given point of time. The title bar of the active editor or view looks different from all the
others.
The UI elements on the menu bar and tool bar represent commands that can be triggered by
an end user.

Using Multiple Windows

Multiple Eclipse Windows can be open at the same time. To open a new window, click on
the Windows menu and select the New Window menu item.
Each window can have a different perspective open in them. For example you could open
two Eclipse windows one in the Java perspective and the other in the Debug perspective.
The window showing the Java perspective can be used for editing the java code and the
window showing the debug perspective can be used for debugging the application being
developed.

Typical Eclipse Menus

The typical menus available on the menu bar of an Eclipse window are −

Sr.N Menu Name & Description


o

File
1 The File menu allows you to open files for editing, close editors, save editor content and rename
files. Among the other things, it also allows you to import and export workspace content and
shutdown Eclipse.

Edit
2
The Edit menu presents items like copy & paste.

Source
3
The Source menu is visible only when a java editor is open. It presents a number of useful menu
items related to editing java source code.

Navigate
4
The Navigate menu allows you to quickly locate resources and navigate to them.

5 Search
9

The Search menu presents items that allow you to search the workspace for files that contain
specific data.

Project
6
The menu items related to building a project can be found on the Project menu.

Run
7
The menu items on the Run menu allow you to start a program in the run mode or debug mode. It
also presents menu items that allow you to debug the code.

Window
8
The Window menu allows you to open and close views and perspectives. It also allows you to
bring up the Preferences dialog.

Help
9
The Help menu can be used to bring up the Help window, Eclipse Marketplace view or Install new
plug-ins. The about Eclipse menu item gives you version information.

3. JAVA

3.1. WHAT IS JAVA?


Java is a programming language and a platform. Java is a high level, robust, object-
oriented and secure programming language.

Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year
1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since
Oak was already a registered company, so James Gosling and his team changed the Oak
name to Java.

3.2. APPLICATIONS OF JAVA


According to Sun, 3 billion devices run Java. There are many devices where Java is currently
used. Some of them are as follows:

1. Desktop Applications such as acrobat reader, media player, antivirus, etc.


10

2. Web Applications such as irctc.co.in, javatpoint.com, etc.


3. Enterprise Applications such as banking applications.
4. Mobile
5. Embedded System
6. Smart Card
7. Robotics
8. Games, etc.

3.3. TYPES OF JAVA APPLICATIONS


There are mainly 4 types of applications that can be created using Java programming:

1) Standalone Application

Standalone applications are also known as desktop applications or window-based


applications. These are traditional software that we need to install on every machine.
Examples of standalone application are Media player, antivirus, etc. AWT and Swing are
used in Java for creating standalone applications.

2) Web Application

An application that runs on the server side and creates a dynamic page is called a web
application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc. technologies are used
for creating web applications in Java.

3) Enterprise Application

An application that is distributed in nature, such as banking applications, etc. is called


enterprise application. It has advantages of the high-level security, load balancing, and
clustering. In Java, EJB is used for creating enterprise applications.

4) Mobile Application

An application which is created for mobile devices is called a mobile application. Currently,
Android and Java ME are used for creating mobile applications.

3.4. FEATURES OF JAVA

The primary objective of Java programming language creation was to make it portable,


simple and secure programming language. Apart from this, there are also some excellent
features which play an important role in the popularity of this language. The features of
Java are also known as java buzzwords.
11

A list of most important features of Java language is given below.

1. Simple
2. Object-Oriented
3. Portable
4. Platform independent
5. Secured
6. Robust
7. Architecture neutral
8. Interpreted
9. High Performance
10. Multithreaded
11. Distributed
12. Dynamic
12

4. PROJECT
4.1. TO GENERATE A ONE TIME PASSWORD
A one-time password (OTP) is a password that is valid for only one login session or
transaction, on a computer system or other digital device. For more details refer this.

4.2. ALGORITHM
Randomly pick characters from our all possibilities and generate a string of the desired length
from it. OTPs are generally 6-7 characters long and randomness in 6-7 characters almost
guarantees a secure way of logging in.

4.3. APPLICATIONS
 OTPs are widely used in websites like- Facebook, Google Sign-in, Wifi –
accessing, Railways Portal Login etc.
 Even the GeeksforGeeks IDE has a unique string for all the codes compiled
through it. For example, https://ide.geeksforgeeks.org/Ks84Ck has the unique
string – “Ks84Ck” at the end which is unique for this code only.

4.4. HOW IT GETS GENERATED ?

Well it is a great possibility that they uses the same algorithm as an OTP is generated. If by
chance (very rare) the unique string generated is already been generated before and has been
associated with a different code then another random string is used.
As per now it seems that only six character strings are generated randomly for a unique
identification of all codes. A time will come when all the possible six character strings may get
exhausted. So yes, even the web-related stuffs also heavily relies on randomness.

Probability Of Collision Of Two OTP's

 The length of OTP is 6 and the set size of all possible characters in the OTP is
62. So the total number of possible sets of the pair of OTPs are 6212.
 Some of them are – [{aaaaaa, aaaaaa}, {aaaaaa, aaaaab},…..{456789, 456788},
{456789, 456789}]
 But the possible sets of equal pair of OTPs are:626. Some of them are –
[{aaaaaa, aaaaaa}, {aaaaab, aaaaab},…..{456788, 456788}, {456789, 456789}]
 Hence the probability of collision of two OTPs is:
6 12 6 -11
62  / 62  = 1 / 62  = 1 / 56800235584 = 1.7605561
So the probability of two OTPs colliding are as less probable as the existence of your life on
earth (Ratio of the number of years you will live to the number of years from the start of the
universe and everything in existence).So yes,OTPs are way more secure than static passwords !
13

4.5. GENERATING PASSWORD AND OTP IN JAVA

Many a time we forget our passwords and we opt for Forget password option and within no
time we get a new password at our registered email-ID or phone no. to login our account. And
every time we get a different password.
Sometimes we access our bank accounts while shopping from an online store or many more
ways, in order to verify our transition from the bank account, they send us OTP(One Time
Password) on our registered phone no. or our email-ID, within no time.
The following code explains how to generate such Passwords and OTP within no time and
what code we can use if in case we need to do so.

4.6. PROGRAMS
Java program explaining the generation of Password

// Java code to explain how to generate random


// password

// Here we are using random() method of util


// class in Java
import java.util.*;

public class NewClass


{
public static void main(String[] args)
14

{
// Length of your password as I have choose
// here to be 8
int length = 10;
System.out.println(geek_Password(length));
}

// This our Password generating method


// We have use static here, so that we not to
// make any object for it
static char[] geek_Password(int len)
{
System.out.println("Generating password using random() : ");
System.out.print("Your new password is : ");

// A strong password has Cap_chars, Lower_chars,


// numeric value and symbols. So we are using all of
// them to generate our password
String Capital_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String Small_chars = "abcdefghijklmnopqrstuvwxyz";
String numbers = "0123456789";
String symbols = "!@#$%^&*_=+-/.?<>)";

String values = Capital_chars + Small_chars +


numbers + symbols;

// Using random method


Random rndm_method = new Random();
15

char[] password = new char[len];

for (int i = 0; i < len; i++)


{
// Use of charAt() method : to get character value
// Use of nextInt() as it is scanning the value as int
password[i] =
values.charAt(rndm_method.nextInt(values.length()));

}
return password;
}
}

Note : The password we are generating will change every time. As we have used random()
method to generate the password.
Output :

Java program explaining the generation of OTP(One Time Password)


// Java code to explain how to generate OTP

// Here we are using random() method of util


// class in Java
import java.util.*;
16

public class NewClass


{
static char[] OTP(int len)
{
System.out.println("Generating OTP using random() : ");
System.out.print("You OTP is : ");

// Using numeric values


String numbers = "0123456789";

// Using random method


Random rndm_method = new Random();

char[] otp = new char[len];

for (int i = 0; i < len; i++)


{
// Use of charAt() method : to get character value
// Use of nextInt() as it is scanning the value as int
otp[i] =
numbers.charAt(rndm_method.nextInt(numbers.length()));
}
return otp;
}
public static void main(String[] args)
{
int length = 4;
System.out.println(OTP(length));
}
}
17

Note : 
The OTP we are generating will change every time. As we have used random() method to
generate the OTP.
Output :

5. CONCLUSION
This case study is a thorough surveyed and researched with the help of my group members.
We learned the importance of IDE, especially the importance and advantages of ECLIPSE.
We developed a program on ECLIPSE IDE to generate password and OTP using JAVA
programming language.

You might also like