private void LoadDataSet()
        {
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                adaScheduleDataSet1.EnforceConstraints = false;

                UserTableAdapter userAdapter = new UserTableAdapter();
                userAdapter.Fill(adaScheduleDataSet1.User);

                ScheduleTableAdapter scheduleAdapter = new ScheduleTableAdapter();
                scheduleAdapter.Fill(adaScheduleDataSet1.Schedule);

                SymbolTableAdapter symbolAdapter = new SymbolTableAdapter();
                symbolAdapter.Fill(adaScheduleDataSet1.Symbol);

                ActivityTableAdapter activityAdapter = new ActivityTableAdapter();
                activityAdapter.Fill(adaScheduleDataSet1.Activity);

                adaScheduleDataSet1.EnforceConstraints = true;
            }
            catch (Exception ex)
            {
                ReportError(ex);
            }

            RefreshViews();

            Cursor.Current = Cursors.Default;
        }
Example #2
0
        public MainForm()
        {
            InitializeComponent();

            // create our global RAPI object
            this.rapi = new RAPI();

            // wire in some ActiveSync events
            this.rapi.ActiveSync.Active     += new ActiveHandler(ActiveSync_Active);
            this.rapi.ActiveSync.Disconnect += new DisconnectHandler(ActiveSync_Disconnect);
            this.rapi.ActiveSync.Listen     += new ListenHandler(ActiveSync_Listen);
            this.rapi.ActiveSync.Answer     += new AnswerHandler(ActiveSync_Answer);

            textUpdate   = new EventHandler(TextMarshaler);
            enableUpdate = new EventHandler(EnabledMarshaler);

            using (UserTableAdapter symbolAdapter = new UserTableAdapter())
            {
                using (SqlConnection connection = symbolAdapter.Connection)
                {
                    if (connection.DataSource == "(local)")
                    {
                        this.textBoxServerName.Text = connection.WorkstationId;
                    }
                    else
                    {
                        this.textBoxServerName.Text = connection.DataSource;
                    }
                }
            }
        }
Example #3
0
        static public void setPassword(string Username, string NewPassword, string OldPassword)
        {
            string UserRole;

            if (!authenticateUser(Username, OldPassword, out UserRole))
            {
                throw new ArgumentException("Old Password was incorrect");
            }

            if (!validPassword(NewPassword))
            {
                throw new ArgumentException("Password wasn't valid");
            }

            if (UsernameExists(Username))
            {
                UserTableAdapter userAdapter            = new UserTableAdapter();
                NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
                NuRacingDataSet.UserRow       userRow   = (NuRacingDataSet.UserRow)userTable.Rows[0];

                byte[] salt = CreateSalt();
                byte[] hash = HashPassword(NewPassword, salt);

                userRow.User_PasswordHash = hash;
                userRow.User_PasswordSalt = salt;

                userAdapter.Update(userTable);
            }
            else
            {
                throw new ArgumentException("Username wasn't valid");
            }
        }
        public MainForm()
        {
            InitializeComponent();

            string application = Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;

            this._appDir = Path.GetDirectoryName(application) + "\\";

            // create our global RAPI object
            this.rapi = new RAPI();

            // wire in some ActiveSync events
            this.rapi.ActiveSync.Active     += new ActiveHandler(ActiveSync_Active);
            this.rapi.ActiveSync.Disconnect += new DisconnectHandler(ActiveSync_Disconnect);
            this.rapi.ActiveSync.Listen     += new ListenHandler(ActiveSync_Listen);
            this.rapi.ActiveSync.Answer     += new AnswerHandler(ActiveSync_Answer);

            textUpdate   = new EventHandler(TextMarshaler);
            enableUpdate = new EventHandler(EnabledMarshaler);

            using (UserTableAdapter symbolAdapter = new UserTableAdapter())
            {
                using (SqlConnection connection = symbolAdapter.Connection)
                {
                    if (connection.DataSource == "(local)")
                    {
                        this.textBoxServerName.Text = connection.WorkstationId;
                    }
                    else
                    {
                        this.textBoxServerName.Text = connection.DataSource;
                    }
                }
            }
        }
Example #5
0
        protected void btn_update_Click(object sender, EventArgs e)
        {
            User                    user           = (User)Session["user"];
            UserTableAdapter        ta_user        = new UserTableAdapter();
            CorporationTableAdapter ta_corporation = new CorporationTableAdapter();

            if (txt_oldpassword.Text != user.password)
            {
                lab_tip.Text = "旧密码输入错误";
                txt_oldpassword.Focus();
            }
            else if (txt_newpassword.Text.Length < 6)
            {
                lab_tip.Text = "密码长度不小于六位";
                txt_newpassword.Focus();
            }
            else if (txt_email.Text.Equals(""))
            {
                lab_tip.Text = "请输入邮箱";
                txt_email.Focus();
            }
            else
            {
                ta_user.UpdateUserByEmail(user.name, txt_newpassword.Text, txt_email.Text, user.id);
                Response.Write("<script>alert('更新成功,请前往主页登录。'); window,location.href='../index.aspx';</script>");
            }
        }
Example #6
0
        public static User GetUserByUsername(string Username)
        {
            UserTableAdapter localAdapter = new UserTableAdapter();

            if (string.IsNullOrEmpty(Username))
            {
                return(null);
            }

            User theUser = null;

            try
            {
                UserDS.UserDataTable table = localAdapter.GetUserByUsername(Username);

                if (table != null && table.Rows.Count > 0)
                {
                    UserDS.UserRow row = table[0];
                    theUser = FillUserRecord(row);
                }
            }
            catch (Exception q)
            {
                log.Error("An error was ocurred while geting user data", q);
            }
            return(theUser);
        }
Example #7
0
        private void LoadDataSet()
        {
            Cursor = Cursors.WaitCursor;
            try
            {
                _dataSet.EnforceConstraints = false;

                UserTableAdapter UserAdapter = new UserTableAdapter();
                UserAdapter.Fill(_dataSet.User);

                ScheduleTableAdapter scheduleAdapter = new ScheduleTableAdapter();
                scheduleAdapter.Fill(_dataSet.Schedule);

                ActivityTableAdapter activityAdapter = new ActivityTableAdapter();
                activityAdapter.Fill(_dataSet.Activity);

                _dataSet.EnforceConstraints = true;

                FillUserList();
            }
            catch (Exception ex)
            {
                ReportError(ex);
            }

            Cursor = Cursors.Default;
        }
Example #8
0
        public ActionResult UserAccessRights()
        {
            ScorecardApplication.Models.UserAccessRights model = new ScorecardApplication.Models.UserAccessRights();
            UserTableAdapter UserTA           = new UserTableAdapter();
            dsScorecard      ScorecardDataset = new dsScorecard();

            UserTA.Fill(ScorecardDataset.User);
            model.UserList = new List <Models.User>();
            UserLevelTableAdapter UserLevelTA = new UserLevelTableAdapter();

            UserLevelTA.Fill(ScorecardDataset.UserLevel);


            foreach (dsScorecard.UserRow UserRow in ScorecardDataset.User)
            {
                dsScorecard.UserLevelRow UserLevelRow = ScorecardDataset.UserLevel.FindByUserLevelID(UserRow.UserLevelID);
                UserLevel UserLevelItem = new UserLevel {
                    decription = UserLevelRow.Description
                };

                User UserItem = new User
                {
                    firstname    = UserRow.FirstName,
                    surname      = UserRow.Surname,
                    username     = UserRow.Username,
                    emailaddress = UserRow.EmailAddress,
                    userlevel    = UserLevelItem,
                    userid       = UserRow.UserID
                };
                model.UserList.Add(UserItem);
            }

            return(View(model));
        }
Example #9
0
        public static List <User> GetUsersForAutoComplete(string filter)
        {
            List <User> theList = new List <User>();
            User        theData = null;

            try
            {
                UserTableAdapter     localAdapter = new UserTableAdapter();
                UserDS.UserDataTable theTable     = localAdapter.GetUsersForAutocomplete(filter);

                if (theTable != null && theTable.Rows.Count > 0)
                {
                    foreach (UserDS.UserRow theRow in theTable.Rows)
                    {
                        theData = FillUserRecord(theRow);
                        theList.Add(theData);
                    }
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
            return(theList);
        }
Example #10
0
        protected void btn_login_Click(object sender, EventArgs e)
        {
            UserTableAdapter ta_user = new UserTableAdapter();
            DataTable        dt_user = ta_user.GetUserByName(txt_name.Text);

            if (dt_user.Rows.Count > 0)
            {
                User user = new User();
                user.id               = Convert.ToInt32(dt_user.Rows[0]["id"]);
                user.name             = (dt_user.Rows[0]["name"]).ToString();
                user.password         = dt_user.Rows[0]["password"].ToString();
                user.authority        = Convert.ToInt32(dt_user.Rows[0]["authority"]);
                user.email            = dt_user.Rows[0]["email"].ToString();
                user.corporation_id   = Convert.ToInt32(dt_user.Rows[0]["corporation_id"]);
                user.corporation_name = dt_user.Rows[0]["corporation_name"].ToString();

                if (user.password.Equals(txt_psw.Text) && user.corporation_name.Equals(txt_corporation.Text))
                {
                    Session["user"] = user;
                    Response.Redirect("user/user_index.aspx");
                }
                else
                {
                    lab_tip.Text = "用户账户名或企业名称或密码错误";
                }
            }
            else
            {
                lab_tip.Text = "用户账户名或企业名称或密码错误";
            }
        }
Example #11
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 public UserDao()
 {
     _userAdapter = new UserTableAdapter();
     _userTable   = new UserDataTable();
     _userAdapter.Fill(_userTable);
     _rng = new Random();
 }
Example #12
0
        //  Written By James Hibbard
        ///
        /// <summary>
        ///     Checks whether the validity of the password
        /// </summary>
        /// <param name="Username">The users Username</param>
        /// <param name="Password">The input password to check</param>
        /// <param name="userRole">Returns the role they're in (null if incorrect password)</param>
        /// <returns>True if the password is accurate</returns>
        static public bool authenticateUser(string Username, string Password, out string userRole)
        {
            if (!UsernameExists(Username))
            {
                userRole = null;
                return(false);
            }

            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
            NuRacingDataSet.UserRow       userRow   = (NuRacingDataSet.UserRow)userTable.Rows[0];


            if (userRow.User_Active)
            {
                if (userRow.User_PasswordHash.SequenceEqual(HashPassword(Password, userRow.User_PasswordSalt)))
                {
                    userRole = userRow.User_Role;
                    return(true);
                }
            }
            else
            {
                userRole = null;
                return(false);
            }

            userRole = null;
            return(false);
        }
Example #13
0
        public static string GetUserRole(string Username)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();
            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
            NuRacingDataSet.UserRow userRow = (NuRacingDataSet.UserRow)userTable.Rows[0];

            return userRow.User_Role;
        }
Example #14
0
        public UserWrapper GetUserWithID(Guid key)
        {
            //var res = _context.Database.SqlQuery<User>("dbo.User_GetUserByID @UserID={0}", key);
            UserTableAdapter adapter=new UserTableAdapter();
            DBDataSet.UserDataTable tbl = adapter.GetDataById(key);

            return getUserWrapper(tbl.FirstOrDefault());
        }
Example #15
0
        // User aus Datenbank lesen und zurückgeben
        public User GetUser(string UserName)
        {
            var context = new UserTableAdapter();
            var Data    = context.GetData();
            var User    = Data.FirstOrDefault(x => x.Username.Equals(UserName));

            return(User == null ? null : new User(User.Username, User.Passwort, true));
        }
Example #16
0
        //  Written By James Hibbard
        /// <summary>
        ///     Checks if the Username is stored in the database.
        /// </summary>
        /// <param name="Username">The Username to check</param>
        /// <returns>True if the username exists</returns>
        static public bool UsernameExists(string Username)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);

            return(userTable.Rows.Count != 0);
        }
        public async Task <int> CountUsersAsync()
        {
            await Task.CompletedTask;

            using (var tableAdapter = new UserTableAdapter())
            {
                return(tableAdapter.CountUsersQuery() ?? 0);
            }
        }
Example #18
0
        public static string GetUserRole(string Username)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
            NuRacingDataSet.UserRow       userRow   = (NuRacingDataSet.UserRow)userTable.Rows[0];

            return(userRow.User_Role);
        }
Example #19
0
        protected void ValueInit()
        {
            Corporation      corporation = (Corporation)Session["corporation"];
            UserTableAdapter ta_user     = new UserTableAdapter();
            DataTable        dt_user     = ta_user.GetUserByCorId(corporation.id);

            rep_userlist.DataSource = dt_user;
            rep_userlist.DataBind();
        }
Example #20
0
 /// <summary>
 /// Login dell'utente
 /// </summary>
 /// <param name="user">username proposto</param>
 /// <param name="pwd">password proposta</param>
 /// <returns>true se le credenziali sono valide</returns>
 public static bool Validate(string user, string pwd)
 {
     UserTableAdapter ta = new UserTableAdapter();
     dtFunblades.UserDataTable u = ta.GetUser(user);
     if (u.Rows.Count>0)
     {
         return (((dtFunblades.UserRow)u.Rows[0]).Password.Equals(pwd));
     }
     return false;
 }
Example #21
0
        public void resetData()
        {
            if (!beenChanged)
            {
                UserTableAdapter userAdapter            = new UserTableAdapter();
                NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(username);
                NuRacingDataSet.UserRow       userRow   = (NuRacingDataSet.UserRow)userTable.Rows[0];

                setData(userRow);
            }
        }
        public async Task DeleteUserAsync(UserModel user)
        {
            await Task.CompletedTask;

            using (var tableAdapter = new UserTableAdapter())
            {
                tableAdapter.Delete(
                    user.Id
                    );
            }
        }
Example #23
0
 public void SetUp()
 {
     examManager = new ExamManager();
     userAdapter = new UserTableAdapter();
     examAdapter = new examTableAdapter();
     UEAdapter   = new user_examTableAdapter();
     userId      = Convert.ToInt32(userAdapter.InsertUser("test", "123", "ceshiyuan", "male", "158", "*****@*****.**", null));
     examId      = Convert.ToInt32(examAdapter.InsertExam("computer", "easy", 4, 20, 60, 80, DateTime.Parse("2015-10-01"), DateTime.Parse("2015-09-01"),
                                                          DateTime.Parse("2015-09-01"), 0, "Mario", 60, 0, 0));
     ueId = Convert.ToInt32(UEAdapter.InsertUserExamResult(userId, examId, -1, "Do it"));
 }
Example #24
0
        public UserWrapper GetUserWithUsername(string username)
        {
            UserTableAdapter adapter=new UserTableAdapter();
            DBDataSet.UserDataTable tbl = adapter.GetData(username);

            UserWrapper uw=null;
            foreach (DBDataSet.UserRow r in tbl)
            {
                uw = getUserWrapper(r);
            }
            return uw;
        }
Example #25
0
 public void UpdatePhoto(int userId, byte[] pic)
 {
     try
     {
         UserTableAdapter adapter = new UserTableAdapter();
         adapter.UpdatePhoto(pic, userId);
     }
     catch (Exception e)
     {
         Log4NetHelper.WriteErrorLog(typeof(UserManager), e);
     }
 }
Example #26
0
 public void UpdatePassword(string password, int userId)
 {
     try
     {
         UserTableAdapter adapter = new UserTableAdapter();
         adapter.UpdatePassword(password, userId);
     }
     catch (Exception e)
     {
         Log4NetHelper.WriteErrorLog(typeof(UserManager), e);
     }
 }
Example #27
0
 protected void rep_userlist_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName.Equals("delete"))
     {
         UserTableAdapter ta_user = new UserTableAdapter();
         ta_user.DeleteUserById(Convert.ToInt32(e.CommandArgument));
         ValueInit();
     }
     if (e.CommandName.Equals("update"))
     {
         Response.Redirect("user_alterpassword.aspx?id=" + e.CommandArgument);
     }
 }
Example #28
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            using (UserTableAdapter symbolAdapter = new UserTableAdapter())
            {
                using (SqlConnection connection = symbolAdapter.Connection)
                {
                    connection.Open();
                    this.textBoxServerName.Text = connection.WorkstationId;
                }
            }

            connectAsync_Click(sender, e);
        }
Example #29
0
        public static void AddDefaultAdministratorAccess(string Role)
        {
            UserTableAdapter theAdapter = new UserTableAdapter();

            try
            {
                theAdapter.AddDefaultAdministratorAccess(Role);
            }
            catch (Exception q)
            {
                log.Error("An error was ocurred while adding default permission by admin role", q);
            }
        }
Example #30
0
        //  Written By James Hibbard
        /// <summary>
        ///     Sets the Last Activity Date in the database for the given user
        /// </summary>
        /// <param name="Username">The User that was active</param>
        static public void wasActive(string Username)
        {
            if (UsernameExists(Username))
            {
                UserTableAdapter userAdapter            = new UserTableAdapter();
                NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
                NuRacingDataSet.UserRow       userRow   = (NuRacingDataSet.UserRow)userTable.Rows[0];

                userRow.User_LastActivity = DateTime.Now;

                userAdapter.Update(userTable);
            }
        }
        public async Task <IEnumerable <UserModel> > GetUsersAsync()
        {
            await Task.CompletedTask;

            using (var tableAdapter = new UserTableAdapter())
            {
                var users = tableAdapter.GetData()
                            .AsQueryable();

                return(_mapper.ProjectTo <UserModel>(users)
                       .AsEnumerable());
            }
        }
Example #32
0
        // User in Datenbank speichern
        public bool SetUser(User user)
        {
            var context = new UserTableAdapter();

            if (GetUser(user.UserName) != null)
            {
                return(false);
            }

            var Data = context.InsertQuery(user.UserName, user.Passwort);

            return(true);
        }
Example #33
0
 public OesDAL.UserDS.UserDataTable GetUserInformation(int userId)
 {
     try
     {
         UserTableAdapter adapter = new UserTableAdapter();
         return(adapter.GetUserById(userId));
     }
     catch (Exception e)
     {
         Log4NetHelper.WriteErrorLog(typeof(UserManager), e);
     }
     return(null);
 }
Example #34
0
        public void SetUp()
        {
            questionManager = new QuestionManager();

            questionAdapter = new questionTableAdapter();
            examAdapter     = new examTableAdapter();
            eqAdapter       = new EQTableAdapter();
            userAdapter     = new UserTableAdapter();
            answerAdapter   = new exam_answer_detailTableAdapter();
            questionId      = Convert.ToInt32(questionAdapter.InsertQuestion("how do you do?", "a", "b", "c", "d", "a", DateTime.Now, DateTime.Now, 0));
            examId          = Convert.ToInt32(examAdapter.InsertExam("computer", "easy", 4, 20, 60, 80, DateTime.Parse("2015-09-01"), DateTime.Parse("2015-09-01"),
                                                                     DateTime.Parse("2015-09-01"), 0, "Mario", 60, 0, 0));
            eqId = Convert.ToInt32(eqAdapter.InsertEQ(examId, questionId, "how do you do?", "a", "b", "c", "d", "a", 0));
        }
Example #35
0
        public static string[] getUsersInRole(string RoleName)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();
            NuRacingDataSet.UserDataTable userTable = userAdapter.GetData();

            List<string> results = new List<string>();

            foreach (NuRacingDataSet.UserRow userRow in userTable.Rows)
            {
                if (userRow.User_Role == RoleName)
                {
                    results.Add(userRow.User_Username);
                }
            }

            return results.ToArray();
        }
Example #36
0
        public void UpdateUser(UserWrapper user)
        {
            UserTableAdapter adapter=new UserTableAdapter();
            adapter.Update(user.UserID, user.FirstName, user.LastName, user.BirthDate, user.Role,
                           user.UserName, user.Password);

            DiciplineTableAdapter da = new DiciplineTableAdapter();

            foreach (var diciplineWrapper in user.Dicipline)
            {
                da.InsertInterest(user.UserID, diciplineWrapper.DiciplineId);
            }

            SubscriptionTableAdapter sa = new SubscriptionTableAdapter();

            foreach (var subWrapper in user.Subscriptions)
            {
                sa.Insert(subWrapper.UnitCode, subWrapper.UserId);
            }
        }
Example #37
0
        public void AddUser(UserWrapper user)
        {
            UserTableAdapter adapter=new UserTableAdapter();
            adapter.Insert(user.FirstName, user.LastName, user.BirthDate, user.Role, user.UserName, user.Password,
                           user.Salt);

            DBDataSet.UserDataTable res = adapter.GetData(user.UserName);

            DiciplineTableAdapter da=new DiciplineTableAdapter();
            foreach (var diciplineWrapper in user.Dicipline)
            {
                da.InsertInterest(res.FirstOrDefault().UserID, diciplineWrapper.DiciplineId);
            }

            SubscriptionTableAdapter sa=new SubscriptionTableAdapter();
            foreach (var subWrapper in user.Subscriptions)
            {
                sa.Insert(subWrapper.UnitCode, subWrapper.UserId);
            }
        }
Example #38
0
 /// <summary>
 /// Aggiorna il campo "last log in" ad ora. (L'utente dovrebbe aver appena fatto login)
 /// </summary>
 /// <param name="username">utente loggato</param>
 public static void LogInLog(string username)
 {
     UserTableAdapter ta = new UserTableAdapter();
     ta.LoginLog(username);
 }
Example #39
0
 public static void AddUserNameToQuizDb(string username)
 {
     var tableAdapter = new UserTableAdapter();
     tableAdapter.Insert(username);
 }
Example #40
0
 public static string GetUserName(long userId)
 {
     var tableAdapter = new UserTableAdapter();
     var result = tableAdapter.GetUserName(userId);
     foreach (var row in result)
     {
         return row.Name;
     }
     return null;
 }
Example #41
0
        public static long GetUserId(string username)
        {
            var tableAdapter = new UserTableAdapter();
            var dataTable = tableAdapter.GetUserId(username);
            foreach (var row in dataTable)
            {
                return row.UserId;

            }
            return -1;
            /*using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                var questionCmd = new SqlCommand("SELECT UserId FROM [User] WHERE Name = @username",
                    connection);
                questionCmd.Parameters.Add(@"username", SqlDbType.VarChar, 50).Value = username;
                questionCmd.Prepare();
                var reader = questionCmd.ExecuteReader();
                while (reader.Read())
                {
                    return (long) reader["UserId"];
                }
                return -1;
            }*/
        }
Example #42
0
 public static void SetUserActiveStatus(string Username, bool active)
 {
     if (UsernameExists(Username))
     {
         UserTableAdapter userAdapter = new UserTableAdapter();
         NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
         NuRacingDataSet.UserRow userRow = userTable[0];
         if (userRow.User_Active != active)
         {
             //avoid making the connection if possible
             userRow.User_Active = active;
             userAdapter.Update(userTable);
         }
     }
     else
     {
         throw new ArgumentException("Username wasn't valid");
     }
 }
Example #43
0
        public void resetData()
        {
            if (!beenChanged)
            {
                UserTableAdapter userAdapter = new UserTableAdapter();
                NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(username);
                NuRacingDataSet.UserRow userRow = (NuRacingDataSet.UserRow)userTable.Rows[0];

                setData(userRow);
            }
        }
Example #44
0
        //  Written By James Hibbard
        /// <summary>
        ///     Gets the email for the given user    
        /// </summary>
        /// <param name="Username"></param>
        /// <returns></returns>
        public static string getEmail(string Username)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();
            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);

            if (userTable.Rows.Count == 0)
            {
                throw new ArgumentException("Username wasn't a valid user");
            }
            else
            {
                return userTable.Rows[0][userTable.User_EmailColumn].ToString();
            }
        }
Example #45
0
        //Written By Simon Davis
        /// <summary>
        /// Return a list of users of type UserInfo
        /// </summary>
        /// <returns></returns>
        public static List<UserInfo> getAllUsers(bool activeOnly = true)
        {
            List<UserInfo> userList = new List<UserInfo>();

            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetData();

            foreach (NuRacingDataSet.UserRow row in userTable.Rows)
            {
                if (row.User_Active || !activeOnly)
                {
                    userList.Add(new UserInfo(row));
                }
            }

            return userList;
        }
Example #46
0
        internal static bool EmailExists(string Email)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();
            NuRacingDataSet.UserDataTable userTable = userAdapter.GetData();

            foreach (NuRacingDataSet.UserRow userRow in userTable.Rows)
            {
                if (userRow.User_Email == Email)
                {
                    return true;
                }
            }

            return false;
        }
Example #47
0
        //  Written By James Hibbard
        /// <summary>
        ///     Sets the Last Activity Date in the database for the given user
        /// </summary>
        /// <param name="Username">The User that was active</param>
        public static void wasActive(string Username)
        {
            if (UsernameExists(Username))
            {
                UserTableAdapter userAdapter = new UserTableAdapter();
                NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
                NuRacingDataSet.UserRow userRow = (NuRacingDataSet.UserRow)userTable.Rows[0];

                userRow.User_LastActivity = DateTime.Now;

                userAdapter.Update(userTable);
            }
        }
Example #48
0
        //  Written By James Hibbard
        /// <summary>
        ///     Checks if the Username is stored in the database.
        /// </summary>
        /// <param name="Username">The Username to check</param>
        /// <returns>True if the username exists</returns>
        public static bool UsernameExists(string Username)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();
            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);

            return userTable.Rows.Count != 0;
        }
Example #49
0
        public void updateDatabase()
        {
            if (beenChanged)
            {
                UserTableAdapter userAdapter = new UserTableAdapter();
                NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(username);
                NuRacingDataSet.UserRow userRow = (NuRacingDataSet.UserRow)userTable.Rows[0];

                userRow.User_GivenName = givenName;
                userRow.User_Surname = surname;
                userRow.User_Email = email;
                userRow.User_Role = userRole;
                userRow.User_StudentNumber = studentnumber;
                userRow.User_EstGraduationYear = estimatedGraduationYear;
                userRow.User_Degree = degree;
                userRow.User_MedicareNo = medicareNumber;
                userRow.User_Allergies = allergies;
                userRow.User_MedicareNo = medicalConditions;
                userRow.User_DietaryRequirements = dietaryRequirements;
                userRow.User_IndemnityFormSigned = indemnityFormSigned;

                userRow.User_SAE_MemberNo = saeMembershipNumber;
                userRow.User_SAE_Expiry = saeMembershipExpiry;

                userRow.User_CAMS_MemberNo = camsMembershipNumber;
                userRow.User_CAMS_LicenseType = camsLicenseType;

                userRow.User_LicenseNo = driversLicenseNumber;
                userRow.User_LicenseState = driversLicenseState;

                userRow.User_EmergencyContactName = emergencyContactName;
                userRow.User_EmergencyContactNumber = emergencyContactPhoneNumber;

                userRow.User_Created = dateCreated;
                userRow.User_LastLogin = lastLoggedIn;
                userRow.User_LastActivity = lastActivity;
                userRow.User_LastPasswordChanged = passwordLastChanged;
                userRow.User_LastLockoutDate = lastLockedOut;
                userRow.User_Active = isActive;

                userAdapter.Update(userTable);
            }
        }
Example #50
0
        //  Written By James Hibbard
        ///
        /// <summary>
        ///     Checks whether the validity of the password
        /// </summary>
        /// <param name="Username">The users Username</param>
        /// <param name="Password">The input password to check</param>
        /// <param name="userRole">Returns the role they're in (null if incorrect password)</param>
        /// <returns>True if the password is accurate</returns>
        public static bool authenticateUser(string Username, string Password, out string userRole)
        {
            if (!UsernameExists(Username))
            {
                userRole = null;
                return false;
            }

            UserTableAdapter userAdapter = new UserTableAdapter();
            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
            NuRacingDataSet.UserRow userRow = (NuRacingDataSet.UserRow)userTable.Rows[0];

            if (userRow.User_Active)
            {
                if (userRow.User_PasswordHash.SequenceEqual(HashPassword(Password, userRow.User_PasswordSalt)))
                {
                    userRole = userRow.User_Role;
                    return true;
                }
            }
            else
            {
                userRole = null;
                return false;
            }

            userRole = null;
            return false;
        }
Example #51
0
        public static UserInfo addUser(string Username, string Password, string UserRole, string GivenName, string Surname, string Email, string StudentNumber,
            string YearOfGradutation, string DegreeName, string MedicareNumber, string Allergies, string MedicalConditions, string DietaryRequirements,
            bool IndemnityFormSigned, string SAEMembershipNumber, DateTime SAEExpiryDate, string CAMSMembershipNumber, string CAMSLicenseType, 
            string DriversLicenseNumber, string DriversLicenseState, string EmergencyContactName, string EmergencyContactPhoneNumber, bool IsActive = true)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();
            NuRacingDataSet.UserDataTable userTable = userAdapter.GetData();
            NuRacingDataSet.UserRow userRow = userTable.NewUserRow();

            if (UsernameExists(Username))
            {
                throw new ArgumentException("Username already exists");
            }
            if (!isEmailValid(Email))
            {
                throw new ArgumentException("Email isn't in a valid format");
            }
            if (EmailExists(Email))
            {
                throw new ArgumentException("Email already exists");
            }
            if (Password == "")
            {
                StringBuilder builder = new StringBuilder();
                byte[] ByteCode = getByteString(8);

                foreach (byte b in ByteCode)
                {
                    builder.Append(b.ToString("X2"));
                }

                Password = builder.ToString();
            }
            else if (!validPassword(Password))
            {
                throw new ArgumentException("Invalid Password");
            }
            if (!Role.UserRoles.Contains(UserRole))
            {
                throw new ArgumentException("Invalid Role");
            }

            byte[] Salt = CreateSalt();
            byte[] HashedPassword = HashPassword(Password, Salt);

            userRow.User_Username = Username;
            userRow.User_PasswordHash = HashedPassword;
            userRow.User_PasswordSalt = Salt;
            userRow.User_Role = UserRole;
            userRow.User_GivenName = GivenName;
            userRow.User_Surname = Surname;
            userRow.User_Email = Email;
            userRow.User_StudentNumber = StudentNumber;
            userRow.User_EstGraduationYear = YearOfGradutation;
            userRow.User_Degree = DegreeName;
            userRow.User_MedicareNo = MedicareNumber;
            userRow.User_Allergies = Allergies;
            userRow.User_MedicalConditions = MedicalConditions;
            userRow.User_DietaryRequirements = DietaryRequirements;
            userRow.User_IndemnityFormSigned = IndemnityFormSigned;
            userRow.User_SAE_MemberNo = SAEMembershipNumber;
            userRow.User_SAE_Expiry = SAEExpiryDate;
            userRow.User_CAMS_MemberNo = CAMSMembershipNumber;
            userRow.User_CAMS_LicenseType = CAMSLicenseType;
            userRow.User_LicenseNo = DriversLicenseNumber;
            userRow.User_LicenseState = DriversLicenseState;
            userRow.User_EmergencyContactName = EmergencyContactName;
            userRow.User_EmergencyContactNumber = EmergencyContactPhoneNumber;
            userRow.User_Active = IsActive;

            userRow.User_Created = DateTime.Now;
            userRow.User_LastLogin = DateTime.Now;
            userRow.User_LastActivity = DateTime.Now;
            userRow.User_LastPasswordChanged = DateTime.Now;
            userRow.User_LastLockoutDate = DateTime.Now;

            userTable.AddUserRow(userRow);
            userAdapter.Update(userTable);

            EmailManager.newUser(Username, Password, Email);

            return UserInfo.getUser(Username);
        }
Example #52
0
        public static void setPassword(string Username, string NewPassword, string OldPassword)
        {
            string UserRole;

            if (!authenticateUser(Username, OldPassword, out UserRole))
            {
                throw new ArgumentException("Old Password was incorrect");
            }

            if (!validPassword(NewPassword))
            {
                throw new ArgumentException("Password wasn't valid");
            }

            if (UsernameExists(Username))
            {
                UserTableAdapter userAdapter = new UserTableAdapter();
                NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
                NuRacingDataSet.UserRow userRow = (NuRacingDataSet.UserRow)userTable.Rows[0];

                byte[] salt = CreateSalt();
                byte[] hash = HashPassword(NewPassword, salt);

                userRow.User_PasswordHash = hash;
                userRow.User_PasswordSalt = salt;

                userAdapter.Update(userTable);
            }
            else
            {
                throw new ArgumentException("Username wasn't valid");
            }
        }
Example #53
0
        private static bool generateUserPassword(string Username)
        {
            StringBuilder builder = new StringBuilder();
            byte[] ByteCode = getByteString(8);
            foreach (byte b in ByteCode)
            {
                builder.Append(b.ToString("X2"));
            }
            string newPassword = builder.ToString();

            UserTableAdapter userAdapter = new UserTableAdapter();
            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);

            foreach (NuRacingDataSet.UserRow userRow in userTable.Rows)
            {
                if (userRow.User_Username.ToLower() == Username.ToLower())
                {
                    byte[] salt = CreateSalt();
                    byte[] hash = HashPassword(newPassword, salt);

                    userRow.User_PasswordHash = hash;
                    userRow.User_PasswordSalt = salt;

                    userAdapter.Update(userTable);

                    try
                    {
                        EmailManager.sendPasswordResetEmail(Username, newPassword, userRow.User_Email);
                        return true;
                    }
                    catch (Exception)
                    {
                        return false;
                    }
                }
            }
            return false;
        }
Example #54
0
        //Written By Simon Davis
        /// <summary>
        /// Returns a UserInfo object for the specified user
        /// </summary>
        /// <param name="Username">User's username</param>
        /// <returns></returns>
        public static UserInfo getUser(string Username)
        {
            if (!User.UsernameExists(Username))
            {
                throw new ArgumentException("Username wasn't valid");
            }

            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);

            NuRacingDataSet.UserRow userRow = (NuRacingDataSet.UserRow) userTable.Rows[0];

            UserInfo userInfo = new UserInfo(userRow);

            return userInfo;
        }