programming

Ads

 
 

Share on Google+Share on Google+

uday kumar
programming
1 Answer(s)      6 years and 9 months ago
Posted in : Swing AWT
sir howcan i creat a buttion for generating randompassword whose length are fix upto 5-15, the condition is every time we get differnt password. we have to take input from user side as:-
1.Text for which password to be generated.
2.Length of password to be generated.(5-15).
3.Types of password User wants to generat:-
(a). Alphanumeric
(b). Numeric
(c). Alphabetic

OUTPUT:-
Generated Password-JU12H6
Inside filename.txt-Text From User Generated Password

ABCD JU12H6
Ads
View Answers

August 27, 2010 at 11:36 AM


Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;

public class RandomPassword {
public static String getRandomString(int length, String charset) {
Random r= new Random(System.currentTimeMillis());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < length; i++) {
int pos = r.nextInt(charset.length());
sb.append(charset.charAt(pos));
}
return sb.toString();
}
public static void main(String[] args)throws Exception {
File file = new File("C:/filename.txt");
FileWriter fstream = new FileWriter(file,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write("Text From User Generated Password");
out.newLine();

Scanner input=new Scanner(System.in);
System.out.print("Text for which password to be generated: ");
String st=input.nextLine();
System.out.print("Length of password to be generated.(5-15): ");
int len=input.nextInt();
System.out.print("Type of password User wants to generate: Numeric or Alphanumeric or Alphabetic:");
String type=input.next();
if(type.equals("Numeric")){
String charset = "0123456789";
System.out.println("Generated Password- "+RandomPassword.getRandomString(len,charset));
out.write(st+" "+RandomPassword.getRandomString(len,charset));
out.newLine();
}
else if(type.equals("Alphanumeric")){
String charset = "0123456789abcdefghijklmnopqrstuvwxyz";
System.out.println("Generated Password- "+RandomPassword.getRandomString(len,charset));
out.write(st+" "+RandomPassword.getRandomString(len,charset));
out.newLine();
}
else if(type.equals("Alphabetic")){
String charset = "abcdefghijklmnopqrstuvwxyz";
System.out.println("Generated Password- "+RandomPassword.getRandomString(len,charset));
out.write(st+" "+RandomPassword.getRandomString(len,charset));
out.newLine();
}
out.close();
}
}

Thanks

Ads









Related Tutorials/Questions & Answers:
Programming
Programming  Given a number n, write a programming to determine its square root if it is possible, in the contraly case print an appropriate massege on the screen
programming
Java Constructor programming for single and double constructor  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object
Advertisements
network programming
network programming   Tutorial for Network programming and administration
Programming with JSP
Programming with JSP  Who will post me the answer
Java Programming
Java Programming  Hi, What is Java Programming? How I can learn Java Programming in one month? Thanks
Programming with JSP
Programming with JSP  Write a program using jsp that accepts a course code as input and displays the course title the program to which it belongs
Ajax programming
Ajax programming  Hi, How I can start ajax programming easily? I... concept. What should be my starting point for Ajax programming? Thanks   Hi, If you have prior programming experience in any web development
Programming (general)
Programming (general)  I haven't yet started college/university but I'm interested in studying programming. I wondering if programming is difficult or confusing with all the codes you have to learn? Also how many languages would
programming concept
programming concept  Write a program that allows the user to input a total dollar amount for an online shopping order and computes and outputs the shipping cost based on the following schedule
programming of foxpro
programming of foxpro  hello sir , sir i am use the foxpro . but i know about c . sir how can i learn fox pro . i know about something about foxpro
C Programming
C Programming  hi,how can i write a program in C programming to place reservation in air plane from the menu let the user to inter his/her gender(W or M)and draw seats by using ascii codes and choose where he/she will sit
programming error
programming error  I got an error when i did the following program the prg. is to "select the name from database when the age is given for the respective name" error i got is:SQL exception please give me the solution by providing
Socket Programming
Socket Programming  How to connect a computer through IP only and check whether it is up and running? I can't see any method in Socket programming where I can pass only IP address as argument. I need the pass port number also
programming c#
programming c#   create and make use of at least one class with appropriate instance methods to solve the programming problem. use console-based menus to navigate between the functionality offered by the application. at least one
Tutorials   
Java Spring Hibernate Struts Training Change JPanel background color from mouse entered/exit event JTable Pagination Jcombobox JAVA SWING how can i display a pdf file in a jtextarea Crop Image Code in Applet Crop Image Code in Applet Image Manipulation in Swing AWT Applet Ho to get virtual key code. how to show set of images continously using JScrollpane in java how to show set of images continously using JScrollpane in java How to connect on screen keyboard to system. How to connect on screen keyboard to system. query java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings Download. how to open one Jframe from main method call Urgent requirement display shapes i am getting an error in adding a menu item to a menu. I am trying to develop a Image Sliding application but unfortunately its not working... Can any one help me in this Sliding window protocol how to update the value of jslider how to update the value of jslider how to update the value of jslider how to update the value of jslider how to update the value of jslider Jbutton in JTable cells program code java textfield problem swing retrieve data from database in java swing form using prev n next buttons retrieve data from database in java swing form using prev n next buttons How to close a frame on action event of a button from a different class ? searching the data swings for webnms Jpanel allignment pass data from java frame to file code for traffic control system simulation Bank Management System how to maKE Jcombox editable after saveing value init. i havei) aJTextField and one button. when place the cursor or enter anything in the test field then only button should be enabled.by default the button should be disabled. i havei) a jtable with few cloumns and few rows andii) one button. when place the cursor in any of the table's column cell. i need to enable the button.by default the button should be disabled. PDF Comparator i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox. issue on jcombobox

Ads

 
Advertisement null

Ads