Computer Magic
Software Design Just For You
 
 

ASP .NET 2.0 Integrated Authentication – Configure your database…

January 4th, 2006

Just a quick note to those who are testing the waters in the new .NET 2.0 framework. My initial reaction is that it is GREAT. Many new features exist and many old features have been reworked slightly so that the programmer can be more efficient. On great new feature is the ability to use an existing security schema provided by Microsoft. This can save you countless hours.

Previous to .NET, you had to roll your own authorization/authentication solution (generally using session variables). Starting with the first incarnation of .NET, Microsoft gave us the ability to plug in our own authentication code and mark a user object as logged in and populate the roles (groups) that the user belonged to. From that point, you could setup your config files or your code to automate authorization to different areas. This simplified the process greatly. The only down side was finer grained control (to specific records) was often required. This worked great to keep non admin users out of the admin section, but if you wanted admins with varying rights, you were still stuck writing a large amount of code to facilitate this.

With the new release of .NET, you can use a pre-defined database schema as a starting point for your applications security. I don’t know if SQL Express comes with these tables and such already defined, but if you want to add these features to your application, you will probly need to run the aspnet_regsql.exe program (located in C:\Windows\Microsoft.Net\Framework\v2.0.50727 on my machine). When you run this command, you can point to the database you would like to setup. Note that you can use one data base for ALL users for ALL applications if you so choose. Personally, I like to keep different apps seperate as it makes the distribution easier (I write code for many clients and push the final products to their servers at a later date).

The aspnet_regsql.exe program adds many tables and stored procedures to your database which allow you to keep a list of users, their roles (groups), and other custom listings to be added later by you. With this, you have a great staring point for a secure permission based application. Just remember to run aspnet_regsql.exe.

I found this out the hard way after downloading one of the new starter kits for ASP.NET 2.0. The starter kit uses the integrated security and kept complaining about not being able to find aspnet_??? stored procedure. My first guess was that the app was built for SQLExpress (2k5) and I was using SQL 2000, but it turns out that it works just fine with 2000, you just have run the aspnet_regsql.exe program.

Ray Pulsipher

Owner

Computer Magic And Software Design

PHP Tutorial – Lesson 6 HTML Forms are our friends!

December 30th, 2005

It’s been a few days since I posted. The holiday season was great and is generally the only time I actually take some time off. The workaholic in me has finally kicked my butt and has sent me back to the office though, so here goes.

We talked earlier about sending input to a PHP script. So far, we have only discussed making requests via the GET method. The GET method is the method used most often on the internet. 99 percent of the time, when you click a hyperlink, you are using the GET method to retrieve the next page. The URL specified in the hyperlink instructs the browser as to which page to request next. It is common to embed data into these links by using the ? symbol and then following that with name=value pairs. This was discussed in an earlier tutorial in the series. In that tutorial, we entered the data (everything after the ?) on the address bar of the browser. This could easily have been put into a hyperlink URL.

The abillity to send data via a GET request was a great leap forward in interactive web design. The problem was (and still is) that GET has certain limits. A major limit is that many browsers and/or servers have a maximum length. This means that you can only send so much data via a URL (some where around 2K if I remember correctly). This is definatly not big enough for some purposes like uploading a file (an empty word document is around 25K if I remember right). The second major issue with using GET requests is that ALL of the information sent to the PHP script is visible on the address bar. Could you imagine logging into your email, and having your password visible on the address bar? Worse yet, most browsers remember the URLs and it could be sitting there in a list for some later user to inspect!

The solution to the GET problem was to create a new way to submit the data. The POST method does not send the data as part of the URL and therefore solves both problems at the same time. Lets look at an HTTP request in both formats to see the differences and the similarities. Notice that though the location of the information changes, the format (name=value pairs) does not.

GET Request



GET /login.php?user=bob&password=mypassword HTTP/1.0

POST Request



POST /login.php HTTP/1.0

user=bob&password=mypassword

That is an excerpt from the HTTP protocol and is an example of the conversation that goes on between a browser and a web server. See how similar the GET and POST methods are?

POST is NOT better than GET, it is just more appropriate in certain circumstances. When you fill out a form, POST is a great solution. When you are clicking a link, GET is generally the better solution. Hyperlinks can’t do a POST request, only GET (you can get it to do a POST but this requires some trickery that we in the industry call Javascript…).

How do you know when to use one or the other? If you really don’t want to display the information in the URL because it would cause security issues, or if the information that you are sending is very large, then you would use a POST, otherwise, use a GET. GET is more convenient as that is the default for all Hyperlinks. Post generally requires a whole form be involved.

What is this HTML form you mention??
Lets use a very simple form, a login box. A login box allows you to type in your User Name and your Password, and then hit the login button. Want to see an example of a login form? Try going to http://www.hotmail.com. Notice that you get a text box for user name, password, and a sign in button.

If you look at the source for that login box, you will find something similar to the following (This is greatly simplified, if you look at the source for hotmail, you will get TONS of other stuff).



<FORM action="login.php" method="POST">
User Name: <INPUT type=text name=user_name>
Password: <INPUT type=password name=password>
<INPUT type=submit value="Log In">
</FORM>

The form starts with the FORM tag. Notice that the closing FORM tag surrounds ALL the inputs that are in this form. This is important as you can have several different forms one page. By including all the inputs in the appropriate form (between the begning and end FORM tags), the form knows which values to package up and send to the server. Only INPUT items that are in the current form are sent (this includes TEXTAREA and SELECT inputs).

Each INPUT that you want sent to the PHP script gets a name. Notice that there is no name on the Log In button. We don’t need to send the value of the Log In button as it doesn’t really tell us anything. We do want to send the user name and password that the user typed in though, so these each get a name.

INPUT items also have a type. Notice that the text type is a simple text box, the password type is a text box that masks the characters type by showing dots, and the submit type is a button. There are others (radio, checkbox) and other input types that have their own special tag (SELECT, TEXTAREA).

Lets take a step back now and look more at the FORM tag. If you notice, it has an attribute called Method. Method can be either POST or GET. Try both and see the difference (setting it to get makes it act like a hyperlink in that it puts the data on the URL). We generally use POST when dealing with forms so that the data does not show up in the URL (more secure for username and password) and also to avoid having problems with maximum data sizes (there is still a maximum in cases, but it is generally 4 or 8 Meg instead of 2-4K).

Next, there is an attribute called action. This is simply a full or relative URL that says where to submit this information to. In our case, we will have a script called login.php waiting to recieve user names and passwords from our form. You will find in web programming that there are almost always two files for data entry, the form (actual data entry; login_form.php) and the action script (processing of the data entered; login.php). This is important because you need the form for the user to fill out, and then the script that does the processing (saving information into the database, sending an email, etc..).

Lets setup our own login form and script. First, create a file called login_form.php. In this file, paste the following…



<FORM action="login.php" method="POST">
User Name: <INPUT type=text name=user_name>
Password: <INPUT type=password name=password>
<INPUT type=submit value="Log In">
</FORM>

This was exactly the form we discussed earlier in the article.

Next, create a file called login.php and paste the following…



<?php
//Get the user name entered in the form
$user_name = $_POST["user_name"];
// Get the password entered in the form
$password = $_POST["password"];
echo "You entered: $user_name, $password
";
?>

Now, navigate to the form (login_form.php). You should see a form and be able to fill out your information. When you click the login button, the browser will package up the information in the inputs and send them to the script specified in action. Login.php runs and can use the POST array to get the values passed to it (or use the GET array if the information was sent via a GET request). The login script doesn’t actually do anything more than simply echo the information passed to it. If you really want to learn to do authentication in PHP, then come back later on for a future article on the subject.

Give it a try. Once it works, try moving one of the inputs outside of the FORM tag and see what happens?

Forms are the primary means of data entry for web based applications. Make sure you understand this material!

Happy Holidays

Ray Pulsipher

Owner

Computer Magic And Software Design

Make a boot to USB boot disk

December 22nd, 2005

The instructions here are specific to RedHat Fedora Core 2. I will try to note differences between FC2 and later releases. In general, the steps should be the same as those for other releases (Mandrake, etc.)

mkbootdisk
A cool little utility. This will generate a boot disk for your system. This is great because it will pack up YOUR kernel and other files. You NEED to use a boot disk that has the same kernel as your installed system. If you don’t, you will run into problems. For instance, upgrading your kernel on your drive, then using an out dated boot disk will mean that you are still using the old kernel. Not the ideal solution. This means you will have to create a new boot disk every time the kernel changes.

Because you probly can’t boot directly to your USB drive, you will have to use a rescue disk to get at your newly installed linux drive. Boot from CD 1 of the linux install, and at the boot prompt, type:
linux rescue

Once this loads, you should be able to mount your USB drive (substitute your root partition if it is other than sda1):
mount /dev/sda1 /mnt/source

Use the CHROOT command to set your USB drive as the root file system:
chroot /mnt/source

Now, everything will run as if your USB drive was mounted the way it would have been if you could boot from it.

To use the mkboot utility, make sure a floppy is in the drive (one that can be erased!) and type (NOTE: the kernel-version should be replaced with the version of the kernel you want to put on your boot disk. Look in the /boot folder to see which kernels you have available. They start with vmlinuz and end with something similar to 2.6.5-1.452):
mkbootdisk kernel-version

Once you have a floppy boot disk, you have the base to start from. The generated disk has a copy of your current kernel

Extracting the startup information
Now that you have the floppy, you can extract the boot files from it. Why would you want to do that? Most likely your floppy won’t work. The floppy will boot, but it won’t load the USB drivers in time. If you bios doesn’t support booting from USB drives directly, then Linux will try to mount the root file system to your drive before your drive is visible.

You may need to make a directory to mount your floppy to:
mkdir /mnt/floppy

Mount the floppy drive so you can view it’s files:
mount /dev/fd0 /mnt/floppy

Make a directory so we can make our changes. The resulting changes will be too big for the floppy, so don’t try to make the changes directly to the floppy as it will run out of room.
mkdir /bootdisk

Copy all the files from the floppy to the /bootdisk folder
cp -R /mnt/floppy/* /bootdisk

Once that is copied, we are done with the floppy:
umount /mnt/floppy

Go to the temp directory we made:
cd /bootdisk

The file we care about is the initrd.img file. It is actually a file system stored within a compressed file. We want to extract all that so that we can manipulate it and add our USB drivers.
cp initrd.img initrd.gz
gzip -d initrd.gz
mkdir a

FC2 initrd files are loop back file systems. FC3 and later initrd files are cpio archives. This next command depends on what you wich version you are using.
FC2: mount -o loop initrd a; cd a
FC3: cd a; cpio –extract < ../initrd

If we look now, we have a directory full of what looks like another root file system (an etc folder, a bin folder, etc.)

We want to copy our USB drivers to the appropriate location in this boot file structure:
cd lib
cp /lib/modules/???????/kernel/drivers/scsi/scsi_mod.ko .
cp /lib/modules/???????/kernel/drivers/sd_mod.ko .
cp /lib/modules/???????/kernel/drivers/usb/host/ehci-hcd.ko .
cp /lib/modules/???????/kernel/drivers/usb/host/uhci-hcd.ko .
cp /lib/modules/???????/kernel/drivers/usb/host/ohci-hcd.ko .
cp /lib/modules/???????/kernel/drivers/usb/storage/usb-storage.ko .

Make sure to replace the ?????? with the correct version of the kernel you are working with (the one you used in the mkbootdisk command earlier). This is a folder, so you can look and see which versions are available.

The files are the modules that will allow USB drives to be seen by the kernel (USB drives are emulated as scsi drives in Linux, that is the reason for the scsi drivers).

Next, we need to edit the linuxrc file (or possibly init?) so that it will load the drivers at boot time.
cd ..
vi linuxrc

You can use a different editor besides VI if it is available.
Add the following lines AFTER the line that loads the ext3.ko module:
echo Loading USB drivers…
insmod /lib/scsi_mod.ko
insmod /lib/sd_mod.ko
insmod /lib/ehci-hcd.ko
insmod /lib/uhci-hcd.ko
insmod /lib/ohci-hcd.ko
insmod /lib/usb-storage.ko
echo Waiting for USB drive detection…
sleep 5

Save that and exit the text editor.

Those are all the changes we need. Now we need to unmount the boot disk file system:
FC2: cd ..; umount a
FC3: find . | cpio -o -H newc | gzip -9 ../initrd.img; cd ..

You are now ready to burn your own CD. I have a bootable ISO ready to go at http://debug.mine.nu/files/usbbootcd.iso. Copy the vmlinuz and initrd.img files into this ISO and burn the cd.

I prefer working with ISO files in windows. If you do too, then copy the vmlinuz and initrd.img files to a windows machine (via floppy, ftp, network, whatever works for you). I like MagicISO personally (google it to find a download link). You can download it and try it out. Open the ISO from the link above, then simply drag the vmlinuz and initrd.img files into the isolinux folder (it will ask you if you want to over write files, say yes). Then, save the ISO and burn it (with MagicISO, or any other burning program).

Ray Pulsipher

Owner

Computer Magic And Software Design

QuickScan – FAQ

December 22nd, 2005

QuickScan – Icon Scanner FAQ

What is QuickScan?
QuickScan is a utility that will scan whole directories or individual files for available icons. It can even make icons of current images. Once found, you can extract the whole icon for your use!

Extract the whole icon?
Yes, the WHOLE icon! Many icon extractors only grab the current DIB (device independant bit map). This means there could be 5 or more other icons located in this file, each with its own height and width and color depth. If you need a specific sized icon, it is usually better to rip the one that is the correct size. Artists generally do a better job of sizing an image thatn an image editing program.

Is this legal?
Well shucks, you would never rip and modify an icon that you don’t own would you? QuickScan will rip any icon it can find. You have to decide if the use you have in mind is ethical. Like any software, QuickScan can be used for both good and evil.

What if I want to search for a couple differnt icons at once?
Then do it. QuickScan uses threading. This means that while one search is going on, you can start another. How fast this works depends on the speed of your system, but it can handle the feat with no problem.

Hey, it finds icons in all sorts of files, what gives?
QuickScan doesn’t check a files extension before trying to extract icons. It just does every file in its way. This may make it seem like it takes longer than other scanners, but it is searching EVERY file. You will be suprised at what it finds.

Bitmaps are showing up with icons, why?
It is actually generating an icon from the bitmap. How good this looks depends on the size and colors of the bitmap to start with. It isn’t a bad way to quickly make a very small thumb nail type image of a larger graphic.

Great, how can I get a copy?
You can purchase a copy from our website. You will recieve an email within one business day with instructions on how to download and install the program. You can also opt to be mailed a CD of the software for a few dollars more. Check out the product information here http://cmagic.biz/products/quickscan/

What gives, it won’t run!
We wrote QuickScan using the .NET framework. All windows operating systems that are up to date should have that installed already. If not, run your auto update. You can also download the current .NET framework here: http://www.microsoft.com/downloads/details.aspx?FamilyID=262d25e3-f589-4842-8157-034d1e7cf3a3&displaylang=en.

Ray Pulsipher

Owner

Computer Magic And Software Design

Python.NET FAQ

December 22nd, 2005

Python.NET FAQ

What is Python.NET?
This package is designed to allow you to embed the Python scripting engine into an existing .NET application. For instance, I was working on a game engine in C# and wanted to be able to script certain features. Rather than writing my own language, I opted to use Python. It has a C API, but no direct support for being embedded into the .NET environment. This project wraps up much of the dirty work involved in working directly with the Python API and allows you a simpler interface between Python and your application.

It comes in source format?
Do you have visual studio .NET? I used the 2k3 version. When you download the source code and extract it to a folder, you can open the project files in vs .NET. You are then welcome to make changes, or simply compile the project. The resulting DLL file is the file you will link your existing project to. You can actually do all the steps manually without the aid of the visual studio environment, but you are on your own 😀

How do I use it in my projects?
Under the references section of you Solution Explorer (in visual studio .NET), you add a reference to the DLL file. Once this has been done, you can start writing code that utilizes the library. Refer to the tutorials section to see examples.

How much does this cost?
Nothing, as long as you use it within the terms of the license (you agreed to it when you downloaded the source code). You can re-use the library in your own project free of charge, as long as you don’t make money off the library directly (as per terms of the license). Feel free to make changes and enhancements to meet your needs. Also feel free to submit changes to me for inclusion in the main code branch.

What if I get stuck?
Check out the forums for answers. Post your questions here. I or others like me may have enough time and inclination to help you out. Please DO NOT call or email me directly unless you are willing to pay my going rate for support. I would love to help everyone, but unfortunatly there just isn’t enough hours in the day.

What if it doesn’t work?
That is really too bad. Feel free to figure it out and let me know the problem and solution via posts on this forum. If you are really stuck, post your questions here and hopefully some one will get back to you. Remember, that this is free software, be patient and don’t expect to get instant support without paying for it.

How often do you update this project?
Well, there really is no schedule. It will probly be driven by the current needs of the projects I am utilizing it in. If I never need a feature, it isn’t likely I will add it. You are welcome to implement the change and submit it for inclusion into the main branch though.

Ray Pulsipher

Owner

Computer Magic And Software Design


Home | My Blog | Products | Edumed | About Us | Portfolio | Services | Location | Contact Us | Embedded Python | College Courses | Quick Scan | Web Spy | EZ Auction | Web Hosting
This page has been viewed 871014 times.

Copyright © 2005 Computer Magic And Software Design
(360) 417-6844
computermagic@hotmail.com
computer magic