Beispiel #1
0
        private bool checkRecord(string email, string box)
        {
            try
            {
                var temp = LoginTable.Find(item => item.Email == email);
                Console.Write(temp.Password);
                if (SaltPassword.VerifyHash(passwordTextBox.Text, "SHA512", temp.Password) == true)
                {
                    SessionInfo.UserID   = temp.UserLogin;
                    SessionInfo.UserName = temp.Email;

                    Console.WriteLine(SessionInfo.UserID);
                    return(true);
                }
                else
                {
                    return(false);
                }
                ;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(false);
        }
        public async Task <IActionResult> Authenticate([FromBody] Clients cliParam)
        {
            string test = (from c in _context.clients
                           where c.cliMail == cliParam.cliMail
                           select c.cliPassword).FirstOrDefault();

            if (test != null)
            {
                if (SaltPassword.ComparePassword(test, cliParam.cliPassword))
                {
                    var cli = _clientService.Authenticate(cliParam.cliMail, test);

                    if (cli == null)
                    {
                        return(BadRequest(new { message = "Login ou mots de passe incorrect" }));
                    }

                    await _context.SaveChangesAsync();

                    cli.cliPassword = null;

                    return(Ok(cli));
                }
                else
                {
                    return(BadRequest(new { message = "Login ou mots de passe incorrect" }));
                }
            }
            return(BadRequest(new { message = "Login ou mots de passe incorrect" }));
        }
Beispiel #3
0
        public async Task <IActionResult> Authenticate([FromBody] Employer empParam)
        {
            string test = (from c in _context.Employer
                           where c.empLogin == empParam.empLogin
                           select c.empPassword).FirstOrDefault();

            if (test != null)
            {
                if (SaltPassword.ComparePassword(test, empParam.empPassword))
                {
                    var emp = _employerService.Authenticate(empParam.empLogin, test);

                    if (emp == null)
                    {
                        return(BadRequest(new { message = "Username or password is incorrect" }));
                    }

                    await _context.SaveChangesAsync();

                    emp.empPassword = null;

                    return(Ok(emp));
                }
                else
                {
                    return(BadRequest(new { message = "Username or password is incorrect" }));
                }
            }
            return(BadRequest(new { message = "Username or password is incorrect" }));
        }
Beispiel #4
0
        public void InstallServices(IServiceCollection services, IConfiguration configuration)
        {
            SaltPassword saltPass = new SaltPassword();

            configuration.GetSection(nameof(SaltPassword)).Bind(saltPass);
            services.AddSingleton(saltPass);
            services.AddSingleton(new Hash(saltPass));
        }
Beispiel #5
0
        private void signUpButton_Click_1(object sender, EventArgs e)
        {
            var textboxs = new Object[] { firstNameTextBox, lastNameTextBox, emailTextBox, departmentComboBox, passwordTextBox, retypePasswordTextBox, empCodeTextBox, addressTextBox };

            if (!isFilled(textboxs))
            {
                MessageBox.Show("Please fill out the form", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (!agreeCheckBox.Checked)
                {
                    MessageBox.Show("You must agree with conditions and terms", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                var appPath = Application.StartupPath;
                Console.WriteLine(appPath);
                var constring = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + appPath + "\\CriminalRecord.mdf;Integrated Security=True;Connect Timeout=30";
                var con       = new SqlConnection(constring);
                if (con.State != ConnectionState.Open)
                {
                    con.Open();
                }
                var sql = "INSERT INTO UserInformations (First_name, Last_name, Address, Phone, Officer_Department_ID, profile_image) " +
                          "VALUES (@first_name, @last_name, @address, @phone, @officer, @profile_image)" +
                          " SELECT @user_id = SCOPE_IDENTITY(); " +
                          "INSERT INTO LoginInformation(User_Login_ID, Email, Password) " +
                          "VALUES (@user_id, @email , @password)";
                var command = new SqlCommand(sql, con);
                if (checkEmail(emailTextBox.Text) == true)
                {
                    MessageBox.Show("Email's already existed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if (!passwordTextBox.Text.Equals(retypePasswordTextBox.Text))
                    {
                        MessageBox.Show("Retype password not match", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    else
                    {
                        command.Parameters.Add("@first_name", SqlDbType.VarChar, 38).Value = firstNameTextBox.Text;
                        command.Parameters.Add("@last_name", SqlDbType.VarChar, 38).Value  = lastNameTextBox.Text;
                        command.Parameters.Add("@address", SqlDbType.VarChar, 38).Value    = addressTextBox.Text;
                        command.Parameters.Add("@phone", SqlDbType.VarChar, 38).Value      = string.Empty;
                        command.Parameters.Add("@officer", SqlDbType.Int).Value            = 1;
                        command.Parameters.Add("@email", SqlDbType.VarChar, 38).Value      = emailTextBox.Text;
                        var ePass = SaltPassword.ComputeHash(passwordTextBox.Text, "SHA512", null);
                        command.Parameters.Add("@user_id", SqlDbType.Int).Direction       = ParameterDirection.Output;
                        command.Parameters.Add("@password", SqlDbType.VarChar).Value      = ePass;
                        command.Parameters.Add("@profile_image", SqlDbType.VarChar).Value = image;
                        command.ExecuteNonQuery();
                        Console.WriteLine("COMPLETE");
                        Close();
                    }
                }
            }
        }
Beispiel #6
0
 private bool checkRecord(string email, string box)
 {
     try {
         LoginInfo temp = LoginTable.Find(item => item.Email == email);
         Console.Write(temp.Password);
         if (SaltPassword.VerifyHash("JohnWick", "SHA512", temp.Password) == true)
         {
             MessageBox.Show("Welcome My N***a");
             return(true);
         }
         else
         {
             return(false);
         };
     } catch (Exception e) {
         Console.WriteLine(e);
     }
     return(false);
 }
        public async Task <IActionResult> PostClients([FromBody] Clients clients)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            string cliPassword = clients.cliPassword;

            clients.cliPassword = SaltPassword.GetPasswordHash(clients.cliPassword);

            _context.clients.Add(clients);

            await _context.SaveChangesAsync();

            clients.cliPassword = cliPassword;

            await Authenticate(clients);

            clients.cliPassword = null;

            return(CreatedAtAction("GetClients", new { id = clients.cliId }, clients));
        }
Beispiel #8
0
        private void btn_submit_Click(object sender, EventArgs e)
        {
            String appPath   = Application.StartupPath;
            string constring = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + appPath + "\\CriminalRecord.mdf;Integrated Security=True;Connect Timeout=30";

            Console.WriteLine(appPath + "Hello");
            SqlConnection con = new SqlConnection(constring);

            if (con.State != ConnectionState.Open)
            {
                con.Open();
            }
            string     sql     = "INSERT INTO LoginInformation (User_Login_ID, Email, Password) VALUES (@id, @email, @password)";
            SqlCommand command = new SqlCommand(sql, con);

            command.Parameters.Add("@id", SqlDbType.Int).Value            = id;
            command.Parameters.Add("@email", SqlDbType.VarChar, 38).Value = "*****@*****.**";
            string ePass = SaltPassword.ComputeHash("JohnWick", "SHA512", null);

            Console.WriteLine(ePass);
            command.Parameters.Add("@password", SqlDbType.VarChar).Value = ePass;
            command.ExecuteNonQuery();
            Console.WriteLine("COMPLETE");
        }
 public Hash(SaltPassword salt)
 {
     _saltPass = salt;
 }
Beispiel #10
0
 public void PopulateDataBase()
 {
     new EmployeDataService(_cache, _serializer, _errorLogger).PostEmploye(new Employe("Test", SaltPassword.GetPasswordHash("test")));
     new EmployeDataService(_cache, _serializer, _errorLogger).PostEmploye(new Employe("Test2", SaltPassword.GetPasswordHash("test2")));
     new EmployeDataService(_cache, _serializer, _errorLogger).PostEmploye(new Employe("Test3", SaltPassword.GetPasswordHash("test3")));
     new EmployeDataService(_cache, _serializer, _errorLogger).PostEmploye(new Employe("Test3", SaltPassword.GetPasswordHash("test4")));
     new EmployeDataService(_cache, _serializer, _errorLogger).PostEmploye(new Employe("Test4", SaltPassword.GetPasswordHash("test5")));
     new EmployeDataService(_cache, _serializer, _errorLogger).PostEmploye(new Employe("Test5", SaltPassword.GetPasswordHash("test6")));
     new EmployeDataService(_cache, _serializer, _errorLogger).PostEmploye(new Employe("Test6", SaltPassword.GetPasswordHash("test7")));
 }
        private async void BtnSignIn_Clicked(object sender, EventArgs e)
        {
            //nb   https://www.c-sharpcorner.com/article/xamarin-android-create-login-with-web-api-using-azure-sql-server-part-two/
            // int clientId = 0;

            tblUser user = new tblUser()
            {
                EmailAddress = usernameEntry.Text,
                Password     = passwordEntry.Text,
            };

            var json    = JsonConvert.SerializeObject(user);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            HttpClient client = new HttpClient();

            var response = await client.PostAsync(string.Concat("http://192.168.0.53:45455/Api/ClientLogin?EmailAdddress=" + usernameEntry.Text /*, "&Password="******"Progress", null, null, true, MaskType.Black)) {

                var client_post_hash_password = Convert.ToBase64String(
                    SaltPassword.saltHashPassword(
                        Encoding.ASCII.GetBytes(passwordEntry.Text),
                        Convert.FromBase64String(UserInfo.Salt)));
                if (client_post_hash_password.Equals(UserInfo.Password))
                {
                    if (UserInfo.Roles == "Admin")
                    {
                        for (int i = 0; i < 100; i++)
                        {
                            //  progress.PercentComplete = i;
                            await Task.Delay(60);
                        }
                        using (UserDialogs.Instance.Loading("Loading", null, null, true, MaskType.Black))
                        {
                            await Task.Delay(5000);

                            await Navigation.PushAsync(new HomePage());
                        }
                    }
                    else if (UserInfo.Roles == "User")
                    {
                        for (int i = 0; i < 100; i++)
                        {
                            // progress.PercentComplete = i;
                            await Task.Delay(60);
                        }
                        using (UserDialogs.Instance.Loading("Loading", null, null, true, MaskType.Black))
                        {
                            await Task.Delay(5000);

                            await Navigation.PushAsync(new MasterPage(UserInfo.EmailAddress /*,UserInfo.ClientID*/));

                            globalUsername = UserInfo.EmailAddress;

                            //  await Navigation.PushAsync(new TestCode(UserInfo.EmailAddress/*,UserInfo.ClientID*/));
                        }
                    }
                }
                else
                {
                    await DisplayAlert("Login Failed", "Error: Password is incorrect", "Ok");
                }
            }

            //else
            //return JsonConvert.SerializeObject("Wrong Password");
            //}
            else
            {
                await DisplayAlert("Login Failed", "Error: Username is incorrect", "Ok");

                //return JsonConvert.SerializeObject("User not Existing in Database");
            }



            // IMyAPI myAPI;
            // //int userId = 0; ;
            // myAPI = RestService.For<IMyAPI>("http://192.168.0.53:45455");
            // tblUser user = new tblUser();
            // user.UserName = usernameEntry.Text;
            // user.Password = passwordEntry.Text;
            //// user.Id = userId;
            // var results = await myAPI.LoginUser(user);

            // int userId = 2;
            // //userId= Convert.ToInt32(usernameEntry.Text);

            // //if (results.Contains("Success"))

            // //string roles ="User";
            // // {

            // user.Roles = "";

            // if (results.Contains("Pass"))
            //     {
            //         await DisplayAlert("Login", "You have succesful Login", "Ok");
            //         await Navigation.PushAsync(new HomePage());

            //     }

            //     else  if (results.Contains("User"))
            //     {
            //         await DisplayAlert("Login", "You have succesful Login", "Ok");
            //         await Navigation.PushAsync(new UserTabbedPage(userId));

            //     }


            // //}
            // else
            // {

            //     await DisplayAlert("Login", "Failed", "Ok");
            // }
        }