コード例 #1
0
        public bool registerUser(string username, string password)
        {
            HasingService hasingService = new HasingService();


            if (checkUsername(hasingService.sha256Hash(username)))
            {
                SQLiteCommand sqlCommand = new SQLiteCommand(db.connection());

                sqlCommand.CommandText = "insert into user (id, username,password) Values (@id,@username,@password)";
                sqlCommand.Parameters.AddWithValue("id", lastID + 1);
                sqlCommand.Parameters.AddWithValue("username", hasingService.sha256Hash(username));
                sqlCommand.Parameters.AddWithValue("password", hasingService.sha256Hash(password));


                sqlCommand.ExecuteNonQuery();

                db.connection().Close();

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: LoginController.cs プロジェクト: aozturkk/Parosan
        public bool checkUser(string username, string password)
        {
            HasingService hasingService = new HasingService();
            CryptoService cryptoService = new CryptoService();

            string usernameHash = hasingService.sha256Hash(username);
            string passwordHash = hasingService.sha256Hash(password);

            SQLiteCommand sqlCommand = new SQLiteCommand("select * from user where username=@username and password = @password", db.connection());


            sqlCommand.Parameters.AddWithValue("@username", usernameHash);
            sqlCommand.Parameters.AddWithValue("@password", passwordHash);

            SQLiteDataReader reader = sqlCommand.ExecuteReader();
            int count = 0;

            while (reader.Read())
            {
                UserModel.id = reader.GetInt32(reader.GetOrdinal("id"));
                count++;
            }

            reader.Close();
            db.connection().Close();

            if (count == 1)
            {
                UserModel.username = username;
                UserModel.key      = Convert.ToBase64String(cryptoService.generateKey(username + password, 32));
                UserModel.iv       = Convert.ToBase64String(cryptoService.generateKey(username + "parosan", 16));

                return(true);
            }
            else
            {
                return(false);
            }
        }