Beispiel #1
0
 //Login
 private void BtnSubmit_Clicked(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(entPassword.Text) || String.IsNullOrEmpty(entUsername.Text))
     {
         lblError.Text      = "Please enter your credentials first.";
         lblError.IsVisible = true;
     }
     else
     {
         int userID = NetworkUtils.Login(entUsername.Text, entPassword.Text);
         if (userID == 0)
         {
             lblError.Text      = "Not a valid username and password.";
             lblError.IsVisible = true;
         }
         else
         {
             AppProperties.setSavedUserId(userID);
             AppProperties.saveUserName(entUsername.Text);
             if (Application.Current.Properties.ContainsKey("currentGroupID"))
             {
                 String groupName = Application.Current.Properties["currentGroup"].ToString();
                 CreatePage.createHamburgerIcon(new GroupPage(), groupName);
             }
             else
             {
                 CreatePage.createHamburgerIcon(new MainPage(), entUsername.Text);
             }
         }
     }
 }
Beispiel #2
0
        //Insert new users into DB
        public static int insertUser(String userIP, String userName, String password)
        {
            int    userID     = 0;
            String connString = @"Server=youseedatabase.cxj5odskcws0.us-east-2.rds.amazonaws.com,1433;DataBase=yousee;User ID=youseeDatabase; Password=yousee18";

            try
            {
                using (SqlConnection sqlConn = new SqlConnection(connString))
                {
                    String spName       = "insertUser";
                    String passUserName = "******";
                    String passUserIP   = "@userIP";
                    String passPassword = "******";

                    using (SqlCommand command = sqlConn.CreateCommand())
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = spName;
                        command.Parameters.Add(new SqlParameter(passUserIP, userIP));
                        command.Parameters.Add(new SqlParameter(passUserName, userName));
                        command.Parameters.Add(new SqlParameter(passPassword, password));

                        sqlConn.Open();
                        try
                        {
                            //Executes the stored procedure and returns the userID
                            userID = (int)command.ExecuteScalar();
                            AppProperties.setSavedUserId(userID);
                        }
                        catch (Exception exc)
                        {
                            Console.WriteLine(exc.Message);
                            userID = 0;
                        }
                        finally
                        {
                            sqlConn.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            //App.Current.Properties.Add("savedUserID", userID);
            //Console.WriteLine(App.Current.Properties["savedUserID"]);

            return(userID);
        }//end InsertDB