Inlog systeem connectie met een Access database.

Status
Niet open voor verdere reacties.

Seantf

Gebruiker
Lid geworden
23 apr 2013
Berichten
140
Hallo ik probeer een inlog systeem te maken met een access database maar ik kan niet inloggen misschien dat jullie de fout zien ik zie de fout niet meer.
Ik denk persoonlijk dat het iets met die md5 encryptie te maken heeft die we van de docent hebben gekregen maar ik weet niet hoe ik deze moet gebruiken.

Alvast bedankt.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Scooter
{
    public partial class frmScooterworld : Form
    {
        public frmScooterworld()
        {
            InitializeComponent();
        }

        public string MD5(string waarde)
        {
            string retourwaarde = "";
            byte[] gegevens = System.Text.Encoding.ASCII.GetBytes(waarde);

            System.Security.Cryptography.MD5CryptoServiceProvider X =
                new System.Security.Cryptography.MD5CryptoServiceProvider();

            gegevens = X.ComputeHash(gegevens);

            for (int i = 0; i < gegevens.Length; i++)
            {
                retourwaarde += gegevens[i].ToString("x2").ToLower();
            }

            return retourwaarde;
        }

        private void btnAnnuleren_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnFactuur_Click(object sender, EventArgs e)
        {
            Factureren f2 = new Factureren();
            this.Hide();
            f2.ShowDialog(); 
           
        }


        public void btnInloggen_Click(object sender, EventArgs e)
        {

            OleDbConnection Verbinding = new OleDbConnection();
            OleDbCommand Cmd;
            OleDbDataReader ObjReader = null;
             try
            {
                string ConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;
                                    Data Source=..\..\..\Scooter.accdb;
                                    Persist Security Info=False;";

                Verbinding.ConnectionString = ConnStr;
                Verbinding.Open();
                ObjReader = null;

                Cmd = new OleDbCommand("select * FROM gebruiker WHERE gebruikerID='" + txtGebruikersNaam.Text + "' AND wachtwoord='" + txtWachtwoord.Text + "'", Verbinding);
                ObjReader = Cmd.ExecuteReader();
                if (ObjReader.Read() == true)
                {
                    MessageBox.Show("Login succes");
                }
                else
                {
                    MessageBox.Show("Gebruikersnaam en wachtwoord zijn ongeldig.");
                }
                    
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                
            }
            finally
            {
                if (ObjReader != null) ObjReader.Close();
                if (Verbinding != null) Verbinding.Close();
            }
        }
    }
 }
 
Laatst bewerkt door een moderator:
Dit is de verkeerde category, je hebt met c# te maken, dit is geen c/c++.

Ik geloof dat die md5 methode wel goed zit. Wordt er een exception opgevangen in dat catch block? kun je meer vertellen over wat er niet werkt?
 
Verplaatst van C / C++ naar C#
 
Mocht het nog steeds niet werken hier is een werkende classe:

Code:
using System;
using System.Security.Cryptography;
using System.Text;

namespace Scooter
{
    class phpBBCryptoServiceProvider
    {
        private string itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

        public bool phpbbCheckHash(string password, string hash)
        {
            if (hash.Length == 34) return (hashCryptPrivate(ASCIIEncoding.ASCII.GetBytes(password), hash, itoa64) == hash);
            return false;
        }

        public string phpbb_hash(string password)
        {
            byte[] random =  ASCIIEncoding.ASCII.GetBytes(new Random().Next(100000, 999999).ToString());

            string hash = hashCryptPrivate(ASCIIEncoding.ASCII.GetBytes(password), hashGensaltPrivate(random, itoa64), itoa64);

            if (hash.Length == 34) return hash;

            return sMD5(password);
        }

        private string hashCryptPrivate(byte[] password, string genSalt, string itoa64)
        {
            string output = "*";
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            if (!genSalt.StartsWith("$H$")) return output;
            //   $count_log2 = strpos($itoa64, $setting[3]);
            int count_log2 = itoa64.IndexOf(genSalt[3]);
            if (count_log2 < 7 || count_log2 > 30) return output;

            int count = 1 << count_log2;
            byte[] salt = ASCIIEncoding.ASCII.GetBytes(genSalt.Substring(4, 8));

            if (salt.Length != 8) return output;

            byte[] hash = md5.ComputeHash(Combine(salt, password));

            do
            {
                hash = md5.ComputeHash(Combine(hash, password));
            } while (count-- > 1);

            output = genSalt.Substring(0, 12);
            output += hashEncode64(hash, 16, itoa64);

            return output;
        }

        private byte[] Combine(byte[] b1, byte[] b2)
        {
            byte[] retVal = new byte[b1.Length + b2.Length];
            Array.Copy(b1, 0, retVal, 0, b1.Length);
            Array.Copy(b2, 0, retVal, b1.Length, b2.Length);
            return retVal;
        }

        private string hashEncode64(byte[] input, int count, string itoa64)
        {
            string output = "";
            int i = 0; int value = 0;

            do
            {
                value = input[i++];
                output += itoa64[value & 0x3f];

                if (i < count) value |= input[i] << 8;
                output += itoa64[(value >> 6) & 0x3f];
                if (i++ >= count)
                    break;

                if (i < count) value |= input[i] << 16;
                output += itoa64[(value >> 12) & 0x3f];
                if (i++ >= count)
                    break;

                output += itoa64[(value >> 18) & 0x3f];

            } while (i < count);
            
            return output;
        }

        private string hashGensaltPrivate(byte[] input, string itoa64)
        {
            int iteration_count_log2 = 6;

            string output = "$H$";
            output += itoa64[Math.Min(iteration_count_log2 + 5, 30)];
            output += hashEncode64(input, 6, itoa64);

            return output;
        }

        private string sMD5(string password)
        { return sMD5(password, false); }

        private string sMD5(string password, bool raw)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            if (raw) return Encoding.ASCII.GetString(md5.ComputeHash(Encoding.ASCII.GetBytes(password)));
            else return BitConverter.ToString(md5.ComputeHash(Encoding.ASCII.GetBytes(password))).Replace("-", "");
        }
    }
}
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan