//Hash the passed in password, then check it against the stored user's password public bool CheckIfValidLogin(string username, string password) { bool valid = false; UserDAO dao = new UserDAO(); UserVO loginCompare; string hashedPass = HashPassword(password); System.Diagnostics.Debug.WriteLine("In checkifvalidlogin, username: " + username); //If you can't find a user under that name, throw the exception try { loginCompare = dao.GetUser(username); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); throw new Exception(USERNAME_DOES_NOT_EXIST_EXCEPTION); } //If the password is not equal, throw the exception if (hashedPass.Equals(loginCompare.Password)) { valid = true; } else { throw new Exception(PASSWORD_INCORRECT_EXCEPTION); } return valid; }
public void CreateNewComment(string username, string commentContents, int subID, int pcID) { CommentDAO dao = new CommentDAO(); UserDAO userDAO = new UserDAO(); CommentVO comment = new CommentVO(); if (commentContents == null) { throw new Exception("You need to enter a comment"); } comment.UserID = userDAO.GetUser(username).UserID; comment.CommentContents = commentContents; comment.PostDate = DateTime.Now; comment.Rating = 0; if (pcID != 0) { comment.ParentCommentID = pcID; } comment.SubmissionID = subID; dao.InsertComment(comment); }
public void CreateNewSubmission(string title, string link, string username) { SubmissionDAO dao = new SubmissionDAO(); UserDAO userDAO = new UserDAO(); SubmissionVO newSub = new SubmissionVO(); if (title == null) { throw new Exception("You need to enter a title"); } if (link == null) { throw new Exception("You need to enter a link"); } newSub.Title = title; newSub.Link = link; newSub.Rating = 0; newSub.PostTime = DateTime.Now; newSub.UserID = userDAO.GetUser(username).UserID; dao.InsertSubmission(newSub); }
//True if taken, false if not taken private bool CheckIfUsernameTaken(string username) { bool taken = true; UserDAO dao = new UserDAO(); UserVO vo; //Try to grab a vo with the name passed in. If it throws //an exception, that means it couldn't find a user with that name try { vo = dao.GetUser(username); Console.WriteLine("CheckIfUsername: " + vo.Username); } catch (Exception e) { taken = false; } return taken; }
public UserVO GetUser(string username) { UserDAO dao = new UserDAO(); return dao.GetUser(username); }
public UserVO GetUser(int uID) { UserDAO dao = new UserDAO(); return dao.GetUser(uID); }