コード例 #1
0
        public async Task <Boolean> RegisterCustomer(Customer customer)
        {
            var email = customer.Email;

            customer.Pass_word = HashAndSalt.HashSalt(customer.Pass_word);
            using (IDbConnection dbConnection = Connection)
            {
                string sQuery0 = "SELECT FirstName FROM Customer WHERE Email = @email";
                dbConnection.Open();
                String result = dbConnection.QueryFirstOrDefault <String>(sQuery0, new { @Email = email });
                dbConnection.Close();

                if (string.IsNullOrEmpty(result))
                {
                    customer.VerifiCode = VerifiCodeGenarator.CreateRandomPassword();
                    customer.Validated  = false;
                    string sQuery = "INSERT INTO Customer(FirstName,LastName,Pass_word,Email,MobileNo,VerifiCode,Validated)" +
                                    "VALUES(@FirstName,@LastName,@Pass_word,@Email,@MobileNo,@VerifiCode,@Validated)";

                    dbConnection.Open();
                    //dbConnection.Execute(sQuery, new { customer.FirstName = FirstName , VerifiCode = vCode });
                    dbConnection.Execute(sQuery, customer);
                    Senders emailsender = new Senders();
                    await emailsender.SendEmailAsync("*****@*****.**", customer.VerifiCode);

                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        private void btn_registreren_Click(object sender, EventArgs e)
        {
            SomerenLogic.Account_Service accountToevoegen = new SomerenLogic.Account_Service();
            Account     nieuwAccount     = new Account();
            HashAndSalt hashPassword     = new HashAndSalt();
            string      salt             = hashPassword.CreateSalt(64);
            string      hashedWachtwoord = hashPassword.GenerateHash(txtbox_nieuwePassword.Text, salt);

            nieuwAccount.Gebruikersnaam = txtbox_nieuweUser.Text;
            nieuwAccount.Wachtwoord     = hashedWachtwoord;
            nieuwAccount.AdminStatus    = "user";
            nieuwAccount.Vraag          = txtBox_geheimeVraag.Text;
            nieuwAccount.Antwoord       = txtBox_geheimAntwoord.Text;
            nieuwAccount.Salt           = salt;

            if (txtbox_licentieSleutel.Text == "XsZAb-tgz3PsD-qYh69un-WQCEx")
            {
                accountToevoegen.AccountToevoegen(nieuwAccount);
                this.Hide();
                LoginScreen loginScreen = new LoginScreen();
                loginScreen.Show();
            }
            else
            {
                MessageBox.Show("Foute licentieSleutel..");
            }
        }
コード例 #3
0
        private void btn_Login_Click_1(object sender, EventArgs e)
        {
            Account_Service service     = new Account_Service();
            Account         currentUser = new Account();

            currentUser.Gebruikersnaam = txtbox_Gebruikersnaam.Text;
            string salt = service.GetSalt(currentUser);

            HashAndSalt retrieve = new HashAndSalt();
            string      hash     = retrieve.GenerateHash(txtbox_Wachtwoord.Text, salt);

            SqlConnection  con = new SqlConnection(@"Data Source=den1.mssql8.gear.host;Initial Catalog=pdb1920f6;Persist Security Info=True;User ID=pdb1920f6;Password=Lc9e~P-O3L2d");
            SqlDataAdapter sda = new SqlDataAdapter("SELECT COUNT(*) FROM ACCOUNT WHERE Gebruikersnaam ='" + txtbox_Gebruikersnaam.Text + "' AND Hash ='" + hash + "'", con);
            DataTable      dt  = new DataTable();

            sda.Fill(dt);
            if (dt.Rows[0][0].ToString() == "1")
            {
                this.Hide();
                SomerenUI UI = new SomerenUI();
                UI.Show();

                UI.GetUserName(txtbox_Gebruikersnaam.Text);
            }
            else
            {
                MessageBox.Show("Foute gebruikersnaam en/of wachtwoord..");
            }
        }
コード例 #4
0
        internal int postUser(User user)
        {
            HashAndSalt pwSecurity = new HashAndSalt();
            int         result     = -999999;
            string      password   = user.Password;
            string      salt       = pwSecurity.getSalt();
            //.GenerateHash(password, salt, 0) the last 0 is the starting value for the recursive iteration counter
            string saltedPassword = pwSecurity.GenerateHash(password, salt, 0);

            password      = ""; //ERASING IT FROM MEMORY
            user.Password = saltedPassword;
            user.Salt     = salt;

            rulesencyclopediaDBEntities1 context = new rulesencyclopediaDBEntities1();

            try
            {
                //getting back the key for the created user.
                context.User.Add(user);
                result = context.SaveChanges();
            }
            catch (EntityException ex)
            {
                exHandler.exceptionHandlerEntity(ex, "something went wrong when posting user");
            }
            finally
            {
                context.Dispose();
            }
            return(result);
        }
コード例 #5
0
ファイル: UserEntity.cs プロジェクト: OmerCD/Ecommerce
        public bool CheckPassword(string password)
        {
            var bytePassword      = Encoding.UTF8.GetBytes(password);
            var newHashedPassword = HashAndSalt.GenerateSaltedHash(bytePassword, Salt);

            return(newHashedPassword.CompareByteArrays(HashedPassword));
        }
コード例 #6
0
ファイル: UserEntity.cs プロジェクト: OmerCD/Ecommerce
        public void SetPassword(string password)
        {
            var bytePassword = Encoding.UTF8.GetBytes(password);

            Salt           = HashAndSalt.GetSalt(SaltLength);
            HashedPassword = HashAndSalt.GenerateSaltedHash(bytePassword, Salt);
        }
コード例 #7
0
        public UserModel RegisterShopOwner(ShopOwner shopowner)
        {
            var email = shopowner.Email;

            shopowner.Pass_word = HashAndSalt.HashSalt(shopowner.Pass_word);
            using (IDbConnection dbConnection = Connection)
            {
                string sQuery0 = "SELECT FirstName FROM ShopOwner WHERE Email = @email";
                dbConnection.Open();
                String result = dbConnection.QueryFirstOrDefault <String>(sQuery0, new { @Email = email });
                dbConnection.Close();

                if (string.IsNullOrEmpty(result))
                {
                    String VerifiCode = VerifiCodeGenarator.CreateRandomPassword();
                    shopowner.VerifiCode = VerifiCode;
                    shopowner.Validated  = false;
                    string sQuery = "INSERT INTO ShopOwner(FirstName,LastName,Pass_word,Email,MobileNo,VerifiCode,Validated)" +
                                    "VALUES(@FirstName,@LastName,@Pass_word,@Email,@MobileNo,@VerifiCode,@Validated)";

                    dbConnection.Open();
                    dbConnection.Execute(sQuery, shopowner);
                    dbConnection.Close();

                    SendMail(email, VerifiCode);

                    string sQuery1 = "SELECT ShopOwnerId from ShopOwner where Email = @email";
                    string ID      = dbConnection.QueryFirstOrDefault <String>(sQuery1, new { @Email = email });

                    UserModel user = null;
                    user = new UserModel {
                        Id = ID, Name = shopowner.FirstName, Email = shopowner.Email
                    };
                    //String Token = BuildToken(user);
                    //return new OkObjectResult(new { token = Token });
                    return(user);
                }

                return(null);
            }

            /* var method = typeof(TokenCreator).GetMethod("createToken");
             * var action = (Action<TokenCreator>)Delegate.CreateDelegate(typeof(Action<TokenCreator>), method);
             * action(user);*/

            //TokenCreator tokencreator = new TokenCreatorC();
            //return tokencreator.createToken(user);
        }
コード例 #8
0
        public UserModel LoginCustomer(Login login)
        {
            String checkUserName;
            string ID;

            login.Pass_word = HashAndSalt.HashSalt(login.Pass_word);

            var email    = login.Email;
            var password = login.Pass_word;

            using (IDbConnection dbConnection = Connection)
            {
                string sQuery  = "SELECT FirstName FROM Customer WHERE Email = @Email AND Pass_word = @Pass_word";
                string sQuery1 = "SELECT CustomerId from Customer where Email = @email";

                dbConnection.Open();
                checkUserName = dbConnection.QueryFirstOrDefault <String>(sQuery, new { @Email = email, @Pass_word = password });
                dbConnection.Close();
                dbConnection.Open();
                ID = dbConnection.QueryFirstOrDefault <String>(sQuery1, new { @Email = email });
                dbConnection.Close();
            }

            if (String.IsNullOrEmpty(checkUserName))
            {
                return(null);
            }
            else
            {
                UserModel user = null;
                user = new UserModel {
                    Id = ID, Name = checkUserName, Email = email
                };
                return(user);

                /* var method = typeof(TokenCreator).GetMethod("createToken");
                 * var action = (Action<TokenCreator>)Delegate.CreateDelegate(typeof(Action<TokenCreator>), method);
                 * action(user);*/

                //TokenCreator tokencreator = new TokenCreatorC();
                //return tokencreator.createToken(user);
            }
        }
コード例 #9
0
        private async void btn_PasswordWasChanged_Clicked(Object sender, EventArgs e)
        {
            showMyData();
            string SaltedPassword = HashAndSalt.CreateSalt().Trim(' ');
            string uName          = userName.Text;
            string email          = myEmail.Text;
            string password       = HashAndSalt.HashString(String.Format("{0}{1}", myPassword.Text, SaltedPassword));
            string password2      = HashAndSalt.HashString(String.Format("{0}{1}", myPassword2.Text, SaltedPassword));

            if (Database.changePassword(password, SaltedPassword, SpecificUser.UserID))
            {
                await DisplayAlert("Super", "Dein Passwort wurde erfolgreich geändert", "Ok");

                App.Current.MainPage = new NavigationPage(new MainPage());
            }
            else
            {
                await DisplayAlert("Fehlgeschlagen", "Dein Passwort wurde nicht geändert :(", "Mist");
            }
            //passwort in Datenbank ändern
        }
コード例 #10
0
        private void btn_enter3_Click(object sender, EventArgs e)
        {
            SomerenLogic.Account_Service AccountNewPassword = new SomerenLogic.Account_Service();
            Account acc = new Account();

            HashAndSalt hashPassword     = new HashAndSalt();
            string      salt             = hashPassword.CreateSalt(64);
            string      hashedWachtwoord = hashPassword.GenerateHash(tb_NewPassword.Text, salt);

            AccountNewPassword.AlterPassword(tb_NewPassword.Text, hashedWachtwoord, salt);

            string gebruikersnaam = tb_GebruiksN.Text;
            string wachtwoord     = tb_NewPassword.Text;

            AccountNewPassword.AlterPassword(gebruikersnaam, hashedWachtwoord, salt);

            MessageBox.Show("Wachtwoord is veranderd");
            LoginScreen login = new LoginScreen();

            login.Show();
            this.Close();
        }
コード例 #11
0
        public bool LoginAdmin(Login login)
        {
            login.Pass_word = HashAndSalt.HashSalt(login.Pass_word);

            var o = login.Email;
            var i = login.Pass_word;

            using (IDbConnection dbConnection = Connection)
            {
                string sQuery = "SELECT FirstName FROM Administer WHERE Email = @Email AND Pass_word = @Pass_word";
                dbConnection.Open();
                checkExist = dbConnection.QueryFirstOrDefault <String>(sQuery, new { @Email = o, @Pass_word = i });
            }

            if (String.IsNullOrEmpty(this.checkExist))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #12
0
        // GET api/login?UserName=pepepe&Password=1234
        public HttpResponseMessage Get([FromUri] string UserName, [FromUri] string Password)
        {
            //Check if username exists
            var dbUser = userDao.checkUserName(UserName);

            //If it does
            if (dbUser != null)
            {
                //check if the password when hashed and salted is equal to the password for the user from the db
                HashAndSalt pwSecurity = new HashAndSalt();
                if (pwSecurity.AreEqual(Password, dbUser.Password, dbUser.Salt))
                {
                    //transfer the db object values to a UserDTO object
                    UserDTO  user  = (UserDTO)DTOConverter.Converter(new UserDTO(), dbUser);
                    TokenDTO token = CheckToken.Instance.userLogin(user);
                    // string token = userDao.getUserFromLogin(UserName, user.Password);
                    if (token != null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, token.token);
                    }
                    else
                    {
                        response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Problem creating token");
                    }
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.Forbidden, "Password is wrong. Try again");
                }
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NoContent, "User does not exist");
            }

            return(response);
        }
コード例 #13
0
        public bool RegisterAdmin(Administer administer)
        {
            var email = administer.Email;

            administer.Pass_word = HashAndSalt.HashSalt(administer.Pass_word);
            using (IDbConnection dbConnection = Connection)
            {
                string sQuery0 = "SELECT FirstName FROM Administer WHERE Email = @email";
                dbConnection.Open();
                String result = dbConnection.QueryFirstOrDefault <String>(sQuery0, new { @Email = email });
                dbConnection.Close();

                if (string.IsNullOrEmpty(result))
                {
                    string sQuery = "INSERT INTO Administer(FirstName,LastName,Pass_word,Email,MobileNo)" +
                                    "VALUES(@FirstName,@LastName,@Pass_word,@Email,@MobileNo)";

                    dbConnection.Open();
                    dbConnection.Execute(sQuery, administer);
                    return(true);
                }
            }
            return(false);
        }
コード例 #14
0
        public async Task <IActionResult> RegisterRider(Rider rider)
        {
            long number;
            var  email = rider.Email;

            rider.Pass_word = HashAndSalt.HashSalt(rider.Pass_word);
            using (IDbConnection dbConnection = Connection)
            {
                string sQuery0 = "SELECT FirstName FROM Rider WHERE Email = @email";
                dbConnection.Open();
                String result = dbConnection.QueryFirstOrDefault <String>(sQuery0, new { @Email = email });
                dbConnection.Close();
                if (string.IsNullOrEmpty(result))
                {
                    rider.VerifiCode = VerifiCodeGenarator.CreateRandomPassword();
                    rider.Validated  = false;
                    string sQuery = "INSERT INTO Rider(FirstName,LastName,Pass_word,Email,MobileNo,VerifiCode,Validated,LicenseNo,Nic)" +
                                    "VALUES(@FirstName,@LastName,@Pass_word,@Email,@MobileNo,@VerifiCode,@Validated,@LicenseNo,@Nic)";

                    dbConnection.Open();
                    dbConnection.Execute(sQuery, rider);
                    dbConnection.Close();
                    string sQuery1 = "SELECT RiderId FROM Rider WHERE Email = @email";
                    dbConnection.Open();
                    String result2 = dbConnection.QueryFirstOrDefault <String>(sQuery1, new { @Email = email });
                    number = Int64.Parse(result2);
                    Image   toupload    = new Image(rider.image, number);
                    Senders emailsender = new Senders();
                    await emailsender.SendEmail(email, rider.VerifiCode);

                    return(await UploadImage(toupload));
                }

                return(new ConflictResult());
            }
        }
コード例 #15
0
        public ShopUserModel LoginShopOwner(Login login)
        {
            String checkUserName;

            login.Pass_word = HashAndSalt.HashSalt(login.Pass_word);

            var email    = login.Email;
            var password = login.Pass_word;

            using (IDbConnection dbConnection = Connection)
            {
                string sQuery = "SELECT FirstName FROM ShopOwner WHERE Email = @Email AND Pass_word = @Pass_word";
                dbConnection.Open();
                checkUserName = dbConnection.QueryFirstOrDefault <String>(sQuery, new { @Email = email, @Pass_word = password });



                if (String.IsNullOrEmpty(checkUserName))
                {
                    return(null);
                }
                else
                {
                    string OwnerID;
                    string sQuery1 = "SELECT ShopOwnerId from ShopOwner where Email = @email";
                    OwnerID = dbConnection.QueryFirstOrDefault <String>(sQuery1, new { @Email = email });
                    string sQuery2 = "SELECT * FROM Shop WHERE OwnerId = @OwnerID";
                    try
                    {
                        dynamic shop = dbConnection.QueryFirst(sQuery2, new { OwnerId = OwnerID });



                        ShopUserModel shopuser = null;
                        shopuser = new ShopUserModel
                        {
                            ShopId      = shop.ShopId,
                            UId         = OwnerID,
                            Name        = checkUserName,
                            Email       = email,
                            Description = shop.Des_cription,
                            Location    = shop.Lo_cation,
                            ShopName    = shop.ShopName,
                            Url         = shop.url,
                            Lat         = shop.Lat,
                            Lng         = shop.Lng,
                        };

                        return(shopuser);
//                        String Token = BuildShopUserToken(shopuser);
//                        return new OkObjectResult(new { token = Token });
                    }
                    catch (Exception e)
                    {
                        return(null);
                    }

                    /* var method = typeof(TokenCreator).GetMethod("createToken");
                     * var action = (Action<TokenCreator>)Delegate.CreateDelegate(typeof(Action<TokenCreator>), method);
                     * action(user);*/
                } //TokenCreator tokencreator = new TokenCreatorC();

                //return tokencreator.createToken(user);
            }
        }