Advertisement
Nasty

Java Sessions

Mar 16th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. package torrete;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.BufferedWriter;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.io.FileReader;
  8. import java.util.Scanner;
  9.  
  10. public class Torrete {
  11.    
  12.     private static String usr = "nasty";
  13.     private static String pwd = "lala";
  14.     private static String pass = usr+"."+pwd;
  15.    
  16.     private static User user;
  17.    
  18.     public static void main(String[] args) {
  19.         checkCache();
  20.         System.out.println("lala");
  21.     }
  22.    
  23.     public static void checkCache() {
  24.         String data = null;
  25.         try {
  26.             BufferedReader br = new BufferedReader(new FileReader("cache.txt"));
  27.             data = br.readLine();
  28.         } catch(IOException e) {
  29.             e.printStackTrace();
  30.         }
  31.         Boolean logged = pass.equals(data);
  32.         if(!logged) {
  33.             login();
  34.         } else {
  35.             System.out.println(pass);
  36.             user = new User(usr);
  37.         }
  38.     }
  39.    
  40.     public static void login() {
  41.         Scanner in = new Scanner(System.in);
  42.         System.out.print("nombre: ");
  43.         String n = in.next();
  44.         System.out.print("clave: ");
  45.         String c = in.next();
  46.         if(n.concat(".").concat(c).equals(pass)) {
  47.             user = new User(n);
  48.             saveCache();
  49.         } else {
  50.             System.out.println("Login bad!! bye:$");
  51.             System.exit(0);
  52.         }
  53.     }
  54.    
  55.     public static void saveCache() {
  56.         try {
  57.             BufferedWriter bw = new BufferedWriter(new FileWriter("cache.txt"));
  58.             bw.write(pass);
  59.             bw.flush();
  60.             System.out.println("Cache saved!");
  61.         } catch(IOException e) {
  62.             e.printStackTrace();
  63.         }
  64.     }
  65.    
  66.     public static class User {
  67.         public String name;
  68.         public User(String name) {
  69.             this.name = name;
  70.             System.out.println("Hello ".concat(this.name));
  71.         }
  72.     }
  73.    
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement