Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package login;
- import javax.inject.Named;
- import javax.enterprise.context.SessionScoped;
- import java.io.Serializable;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import javax.faces.context.FacesContext;
- import javax.servlet.http.HttpSession;
- @Named(value = "variable")
- @SessionScoped
- public class Variable implements Serializable {
- public Variable() {
- }
- String GetsUsername, GetsPassword;
- public static String Name;
- public String getGetsUsername() {
- return GetsUsername;
- }
- public void setGetsUsername(String GetsUsername) {
- this.GetsUsername = GetsUsername;
- }
- public String getGetsPassword() {
- return GetsPassword;
- }
- public void setGetsPassword(String GetsPassword) {
- this.GetsPassword = GetsPassword;
- }
- //User DB
- String ID,
- username,
- Email,
- password,
- State,
- Comment,
- Notification,
- Mail,
- Notes,
- Age,
- Friend,
- Avatar;
- public boolean load() {
- Name = "";
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection MC = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "1234");
- Statement STF = MC.createStatement();
- ResultSet R = STF.executeQuery("Select * from user");
- while (R.next()) {
- username = (R.getString("Name"));
- password = (R.getString("Password"));
- if (GetsUsername.equals(username) && GetsPassword.equals(password)) {
- Name = username;
- return true;
- }
- }
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException E) {
- System.out.println(E);
- }
- return false;
- }
- public String check() {
- if (load()) {
- return "MyPosts.xhtml?faces-redirect=true";
- } else {
- return "login.xhtml?faces-redirect=true";
- }
- }
- public String logout()
- {
- Name = "";
- return "login.xhtml";
- }
- public String getID() {
- return ID;
- }
- public void setID(String ID) {
- this.ID = ID;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getEmail() {
- return Email;
- }
- public void setEmail(String Email) {
- this.Email = Email;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getState() {
- return State;
- }
- public void setState(String State) {
- this.State = State;
- }
- public String getComment() {
- return Comment;
- }
- public void setComment(String Comment) {
- this.Comment = Comment;
- }
- public String getNotification() {
- return Notification;
- }
- public void setNotification(String Notification) {
- this.Notification = Notification;
- }
- public String getMail() {
- return Mail;
- }
- public void setMail(String Mail) {
- this.Mail = Mail;
- }
- public String getNotes() {
- return Notes;
- }
- public void setNotes(String Notes) {
- this.Notes = Notes;
- }
- public String getAge() {
- return Age;
- }
- public void setAge(String Age) {
- this.Age = Age;
- }
- public String getFriend() {
- return Friend;
- }
- public void setFriend(String Friend) {
- this.Friend = Friend;
- }
- public String getAvatar() {
- return Avatar;
- }
- public void setAvatar(String Avatar) {
- this.Avatar = Avatar;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement