Esempio n. 1
0
  public boolean validateUser(String username, String password) {
    AeSimpleSHA1 sha1handler = new AeSimpleSHA1();
    String EncodedPassword = null;
    try {
      EncodedPassword = sha1handler.SHA1(password);
    } catch (UnsupportedEncodingException | NoSuchAlgorithmException et) {
      System.out.println("Can't check your password");
      return false;
    }

    Session session = cluster.connect("ducquak");
    PreparedStatement pS = session.prepare("SELECT * FROM users");
    ResultSet rs = null;
    BoundStatement boundStatement = new BoundStatement(pS);
    rs =
        session.execute( // this is where the query is executed
            boundStatement // here you are binding the 'boundStatement'
            );
    if (rs.isExhausted()) {
      System.out.println("Nothing returned");
      return false;
    } else {
      for (Row row : rs) {

        String userName = row.getString("userName");
        if (userName.equals(username)) {
          String StoredPass = row.getString("password");
          if (StoredPass.compareTo(EncodedPassword) == 0) return true;
        }
      }
    }
    return false;
  }
Esempio n. 2
0
  public boolean registerUser(String username, String Password) {
    AeSimpleSHA1 sha1handler = new AeSimpleSHA1();
    String EncodedPassword = null;
    try {
      EncodedPassword = sha1handler.SHA1(Password);
    } catch (UnsupportedEncodingException | NoSuchAlgorithmException et) {
      System.out.println("Can't check your password");
      return false;
    }
    Session s = cluster.connect("ducquak");
    PreparedStatement pS = s.prepare("INSERT INTO users (userName,password) Values (?,?)");
    BoundStatement boundStatement = new BoundStatement(pS);
    s.execute( // this is where the query is executed
        boundStatement.bind( // here you are binding the 'boundStatement'
            username, EncodedPassword));
    // We are assuming this always works.  Also a transaction would be good here !

    return true;
  }