Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Storing information "Credentials".

  1. #1
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Storing information "Credentials".

    I have the following code:

    //By José D. Hernández, 2013.
     
    import java.io.*; 
    import java.util.Scanner;
     
    public class ugh 
    { 
    	public static void main(String args[]) throws IOException, InterruptedException 
    	{ 
    		String line, usern, passw;
    		CharSequence look = "127.0.0.1";
     
    		Scanner scan = new Scanner (System.in);
     
    		System.out.print("Username: ");
    		usern = scan.next();
     
    		System.out.print ("Password: ");
    		passw = scan.next( );
     
    		Process p=Runtime.getRuntime().exec("cmdkey /list"); 
    		p.waitFor(); 
    		BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); 
    		line=reader.toString();
     
    		while(line!=null) 
    		{ 
     
    			if(line.contains(look)) 
     
    				p=Runtime.getRuntime().exec("mstsc.exe C:\\test.rdp");
     
    			else
    				p=Runtime.getRuntime().exec("cmdkey /generic:TERMSRV/127.0.0.1 /user: " + usern + " /pass: " + passw);
     
    			line=reader.readLine();
    		}
    	}
    }

    I want this Java Program to ask for a "username" and a "password" only the first time I run it and then store it some how and never deletes it (This is where I'm honestly lost).

    The purpose of this Java Program so you can understand it better is to execute the "cmdkey /list" command (which will list all the credentials saved in a local computer) and then read the output of the command and check if certain credentials are saved or not; If they are, my program will just run an .RDP file but if they are not, my program is going to add them, since I provided them first time.

    Then every time the client open this app it wont ask for the user input, and it will just simply check if the credentials are in the local machine, go on or add them again. (Since we are having some difficulties with windows storing some credentials.)

    I hope you guys understand and can help me with this, by the way I'm just a beginner.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Storing information "Credentials".

    Can you save the data in a disk file?
    If the file does not exist, get the data from the user and write the file.
    If the file does exist, read the data from the file.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Storing information "Credentials".

    Thanks you gave me a great Idea, Windows Registry.

Similar Threads

  1. "Program execution skips the "if" statement"!
    By antony1925 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 7th, 2012, 07:15 AM
  2. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  3. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  4. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM