Solved

protected application with user and pw.

Posted on 2000-05-14
8
216 Views
Last Modified: 2013-11-23
I want my application to run only after login.It means that for the first time the app is running, I'll get a login window to insert user and pw and from that first login (the parameters will be written in .ini file) and on, each time someone wants to run this app, he should login with the user and pw he gave at the first time. How can I implement such a utility for the app?
another issue-Is there a way to write these parameters to .ini file but as an enchrypted data? (maybe there are specific classes for that?)
0
Comment
Question by:twg
  • 4
  • 3
8 Comments
 
LVL 3

Accepted Solution

by:
falter earned 60 total points
ID: 2808830
First problem INI-File:

Have a look at Properties class in Java.
You can write an ascii file my.ini like this.
myapp.user=john
myapp.password=doe

You can read this file by writing

Properties myPprops = new Proberties() try {
   myProps.load(new FileInputStream ("my.ini"));
} catch (Exception e) {
}
Now you can query the Properties with
myProps.getProperty("myapp.user",defaultValue);

DefaultValue is used if myapp.user isn't defined or set.

As I know Java has some classes in javax packages allowing encrypting and decrypting. (Never used them)

Another approach may be to provide a serialized class loaded by
ObjectInputStream and written by ObjectOutputStream.
something like
public class MyLoginConfig
{
 protected String user = null;
 protected String password = null;
 public void setUser(String user)
 {
   this.user = user;
 }
 public void setPassword(String passwd)
 {
    this.password = passwd;
 }
 public String getUser() { return user; }
 public String getPassword() { return password; }
 boolean validate(String user, String password)
 {
if (this.user.equals(user) && this.password(equals(password))
 {
   return true;
 } else {
   return false;
 }
}

In your main you can use this class:
File loginCfgFile = new File("login.ser");
if (loginCfgFile.exists()) {
  // readin the serialized object
  // compare the user input with the stored values
} else {
  // accept the input and
  // write the serialized object
}
0
 

Author Comment

by:twg
ID: 2809758
Thanks alot falter.  I thought of using hashCode for strings but there's no reverse function (i.e, getting back the string from the code).
Do you have any idea?
0
 
LVL 3

Expert Comment

by:falter
ID: 2810342
Why didn't try something like Unix systems do with passwords.
They use an one-way algorithm do produce the stored value of a password.
During login they take the user input apply the algorithm and compare the result with the stored one and they have no need to recover the original string from the encrypted one.
May be hashcode is enough for what you want.

Store the hashcode and compare later the hascode of the userinput with the stored one.
0
 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2810360
There isn't a way to get anything back from a hash code, because more than one object can provide the same hash code.  If you want secure encryption (for a high security application) then look into the javax.crypto packages.  Serialization won't work for the following reason: Most of the serialized data will appear as gibberish, but strings are stored as strings in the serialized file and hence are readable by anyone , because it will appear as mostly gibberish to the user.  

So, if you truly want encryption, look into the Java Encryption API.  If you just want privacy, use serialization or simple I/O, but find a way to store the password and username without simply writing them out.  This can partially be accomplished by overwriting writeObject() and readObject() in your serializable class to not output the password/username as strings.

Good luck

Laminamia :)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:twg
ID: 2816527
I used the .ini file to store my parametes.
The problem is that each time I want to add something to the .ini file and I use Properties.store, then it writes everything again to the file instead of just adding. For example:
#preferences
#Wed May 17 12:16:30 IDT 2000
Password=2154053
User=1993601186
#Preferences (if I used .store() again)
#Wed May 17 12:17:14 IDT 2000
Password=2154053
User=1993601186
Param1=test1
Param2=test2.

Is there a way to update the file (like deleting the existing content and rewrite - I didn't find such a method for class 'File' either).



0
 
LVL 3

Expert Comment

by:falter
ID: 2817105
twg,

try

File iniFile = new File("fileName.ini");
if (iniFile.exists())
{
  // file exists so let us delete it
  boolean bRC = iniFile.delete();
}
.... Properties.store...
0
 

Author Comment

by:twg
ID: 2820019
Hi falter, thanks for your answer.
But it means that everytime I want to add something to the file, I have to delete it and create a new file to store the Properties? isn't it a waste of resources?
0
 
LVL 3

Expert Comment

by:falter
ID: 2820474
May be its not a very elegant solution.
You can write your own routines parsing your file and replacing the entries you want.
Also if you only want to append something to the file simply create a
Properties object and write it to the file.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 48
factorial example challenge 10 62
array11 challenge 16 52
wordlen challenge 3 49
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now