Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.squadd.technical; import com.squadd.UI.LoginUI; import com.squadd.javaBeans.Contact; import com.squadd.managers.DBManager; import com.squadd.managers.SHA1Hash; import com.vaadin.ui.Notification; import java.io.UnsupportedEncodingException; import java.security.NoSuchAlgorithmException; /** * * @author SharkNado */ public class Authorizator { public static boolean successAuthorization(LoginUI loginUI, Contact contact) { DBManager manager = new DBManager(); Contact cont = manager.getContactByLogin(loginUI.getUsername().getValue()); if (cont == null) { return false; } else { try { if (cont.getToken().equals(SHA1Password(loginUI))) { contact.setAuthorized(true); contact.setLogin(cont.getLogin()); contact.setId(cont.getId()); contact.setToken(cont.getToken()); contact.setUserInfo(cont.getUserInfo()); return true; } else { return false; } } catch (Exception e) { Notification.show("System error"); return false; } } } private static String SHA1Password(LoginUI loginUI) throws NoSuchAlgorithmException, UnsupportedEncodingException { return SHA1Hash.SHA1(loginUI.getPassword().getValue()); } }