Showing posts from February, 2021

Blazor Edit Form and Validation

      For a class project I'm working on in a secure coding class I wanted to find a way to safely validate form data as to not send malicious values to our API or our database. I was working out how to do this in Blazor, and found the handy EditForm component. It allows you to enter a type of model you'd like the form to build, and in that model we can specify if the form is required and what type of data is allowed in.       In this example we have a couple required fields and we don't allow any special characters into our fields. We also only allow a certain length of string as our input, and simple error messages are displayed when invalid data is passed. When proper or improper data is passed to our form, it looks like this:  

API's in C#

      There is a lot here to take screen shots, but the code is all on my GitHub here if you'd like to follow along with this post.       My wife teaches sixth grade, and lately I've been thinking about an application I could build her to help manager her classroom and motivate the students to improve on the skills they've been struggling with. The concept is to turn a classroom into a game of Dungeons & Dragons, except the skills are in things like math and reading. Students would answer questions instead of rolling dice, and can then add their skills to their results so they can earn experience and rewards. Originally I was going to build this in FastAPI but I thought .NET Core would be better for setting up models and working with a database.     I started by setting up my models in a shared class library project, and I added a Classroom class for tracking classes of students, a Student class for tracking the stats of students and a Logs class to keep track of how a

FastAPI for a Simple Game

      Since I've been having fun with FastAPI, I decided to build an API for a simple game I learned about while studying my textbook for my Advanced Algorithms course. The game is described as two players attempting to move their pieces from one side of the grid to the opposite side. One player moves from the top to the bottom, the other from the left to the right. A piece can move forward one space into an empty space, or it can hop over one empty piece. Once a player's pieces have moved all the way over to the opposite end of the board, that player wins. The author of my textbook said this game was played on a table in a diner using sugar packets, so I decided to call my game 'Packet Swap'.     Anyway, since I wanted to use FastAPI, the logic is in Python. I found what I thought was a pretty good solution by describing the board as a dictionary of tuple keys and strings describing the object in that location. Using tuples as the keys let me do some simple math on on