Generating Password and Otp in Java
Generating Password and Otp in Java
INDEX
3
1. INTRODUCTION
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.
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!
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.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.
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
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
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.
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.
The typical menus available on the menu bar of an Eclipse window are −
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
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.
1) Standalone Application
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
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.
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.
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.
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
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
{
// Length of your password as I have choose
// here to be 8
int length = 10;
System.out.println(geek_Password(length));
}
}
return password;
}
}
Note : The password we are generating will change every time. As we have used random()
method to generate the password.
Output :
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.