473,322 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Simple User/Pass Access

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Test {
  4.     public static void main(String[] args) {
  5.         Scanner input = new Scanner(System.in);
  6.         String username, tempuser;
  7.         username = "testuser";
  8.  
  9.         {System.out.println("Please enter your username.");
  10.         tempuser = input.nextLine();
  11.         if (!tempuser.equals(username)){
  12.             System.out.println("Wrong username.");
  13.             Test.main(null);}
  14.         else 
  15.             Test.Access();
  16.         }
  17.     }
  18.  
  19.     public static void Access() {
  20.         Scanner input2 = new Scanner(System.in);
  21.         String password, temppassword;
  22.         password = "testpass";
  23.  
  24.     System.out.println("Please enter your password.");
  25.         temppassword = input2.nextLine();
  26.  
  27.         if (!temppassword.equals(password)){
  28.             System.out.println("Wrong password.");
  29.             Test.main(null);}
  30.         else
  31.             System.out.println("Access Granted!");}
  32.  
  33.  
  34. }
  35.  
Pastebin of JAVA Code for easier reading.

I am a newbie to Java and have been learning and testing. My question is this, is the code above proper for a simple protected program in its current state?
Mar 22 '12 #1
3 1751
r035198x
13,262 8TB
Typically password are stored in a database. Actually their digests are stored in the database. A digest is a fixed length string created by applying some algorithm to a string in such a way that it is practically impossible to deduce the password given it's digest.
The authentication is then done by comparing digests rather than comparing the actual passwords.
Mar 22 '12 #2
Just for the sake of argument and to stay within my limits, this program is to be used by only me and only on my computer, and therefore I would have the only password. Would the above work?
Mar 22 '12 #3
r035198x
13,262 8TB
Your problem would be that anyone who has access to your program (even the compiled .class files) will be able to open the .class file and see both the user name and password in it.
Mar 22 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: VB Programmer | last post by:
I create a simple user control and exposed a property, "MyProperty". I dragged it onto a new webform. I want to access the exposed property ("MyProperty") of the user control. But, I cannot...
3
by: Davie | last post by:
I am new to .Net, so apologies if this is a simple question. I need a way of display folders and files to my users. However, it must show whether they have NTFS access to the file/folder. For...
9
by: Ben | last post by:
Hi, In ASP.NET website, I have a web page is used to dump raw data into database (SQL Server). The database data will corrupt if two users dump raw data concurrently. How to allow only one...
0
by: | last post by:
I have a simple USer control Page and web form . I added a label into my ascx file wich has "Label" text as default. When i try to change its value in my ascx file's page_load event ...
0
by: redivider | last post by:
I have a app connecting to sqlserver using the ntlogin. I want to verify if the NT user has access to read/read-write to the database/catalog (i figure there is a table of users in the sqlserver...
4
by: mattmao | last post by:
Greetings everyone. I am a college student studying in the University of Technology, Sydney. PHP is not in my studying plan, I am taking subjects about J2EE in this semester. However I do...
1
by: =?Utf-8?B?RGFtaXIgRGV6ZWxqaW4=?= | last post by:
Hi. I have to implement an Java Axis2 web service client in .NET WCF as well a web service to witch a Java Axis2 client will connect. I would like to provide user identification using...
1
by: lathamoulali | last post by:
Hello frnds, I am new to ASP Programming,please help me out with this problem... The site uses the same ASP file but the map is generated when using the anonymous user and other times the map...
0
by: Developer111 | last post by:
My Application is installed on Citrix MetaFrame. I have created some users accounts who login to the server through client Citrix Program Neighborhood. As soon as user login to the server My...
7
by: atul gavali | last post by:
how to avoid user to access same Account from diffrent location? e.g There are 2 person A,B.They have joint account in bank bank balance in their a/c is 5000. there must be a 1000 Rs. in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.