Welcome to Strong Coders Community Sign in | Join | Help

Tuesday, February 13, 2007 6:51 PM

Security Sin #1

There are many sins for good security practices, much more than 7. One of the worst things you can do is force your user to use a specific character set when creating a password. I recently encountered this on Western Union's website, a site meant for transferring money online. This company has a lot of my personal information: Credit Card, Name and Address, previous addresses, a lot of stuff I don't want other people to know. So I went to reset my password because I couldn't seem to remember it, which isn't like me. So I went to reset it, and when I got to the point of asking me for my password, I remembered the password. It was because they don't allow special symbols in their passwords, like # or @. Worse yet, they only allow 16 characters! Now 16 characters is a longer than your average password, but honestly, why limit the number of characters? A user should be able to enter a password of a thousand characters if he wants to, and certainly there is no good reason to prevent users from using some symbols. In fact, secure websites might require symbols in the password.

A good website should never limit what a person can use as characters in their password, and never limit the length. OK, you can limit it to say 1000 characters if you want to, but still, what's the point? If a password is properly hashed and salted, there is no need to worry about the length of the password since it will be the same size all the time. This is a poor security choice, and never let your website commit this sin.

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 1 Comments
Filed under:
Friday, February 02, 2007 11:10 PM

Make Your Programs Impersonate

Sometimes it is useful for your Programs to impersonate under a different user's context. The .NET Framework provides a little help for that, but it still requires a litle help from Platform Invoke.

We can impersonate by using the WindowsIdentity class and calling the Impersonate method on it. The only trick is actually getting a WindowsIdentity for another user. It's easy to get get one for the current user, but requires some work.

Let's say I have a Windows Account named "test" with a password of "TeSt111@", but my current Windows Account is "Kevin Jones" with a password of "notreal". However I programically want to run my program as "test".

By using the WindowsIdentity.Impersonate() method, we can impersonate. However this method expects a Windows Token, and getting a hold of one of those requires some unmanaged code. The unmanaged library we will need is advapi32.dll, which contains an entry point called "LogonUser". This is what we will use to get an impersonation token. This entry point needs a few things. It needs a Username, a domain, a password, the login type, and the login provider. It hands back the token as a reference parameter, and returns true or false as to if the logon was successful. The managed P/Invoke wrapper would look something like this:

[DllImport("advapi32.dll", EntryPoint

= "LogonUser", SetLastError = true )]
public static extern bool LogonUser( string lpszUsername, string lpszDomain,
                              
string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

This is a start. Now to get the token for the test account it would require calling this with the correct things, which might look something like this:

IntPtr token

= IntPtr . Zero;
bool success = LogonUser("test", null , "TeSt111@", 2 , 0 , ref token);
if ( ! success)
{
    
throw new Exception("An error occured logging in.");
}

WindowsImpersonationContext context = WindowsIdentity . Impersonate(token);
//At this point in time, the application is now running as a different context
context . Undo();
//After undo, it goes back to normal.
CloseHandle(token);
//Release the handle to the token.

You see this other method called "CloseHandle" which is another unmanaged call to the kernel, to release the handle to the token. This method as managed code looks like this:

[DllImport("kernel32.dll", EntryPoint

= "CloseHandle", SetLastError = true )]
public static extern bool CloseHandle(IntPtr handle);

Limitations
The only limitation to it is this code assumes you are using a local account, and not Active Directory or that you are on a domain (hence passing null as the domain). In order to do it with a network account, you would need to Duplicate the token, which I will save for another time.

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 0 Comments
Filed under: ,
Monday, December 25, 2006 4:48 AM

Farewell to Doug Reilly

It is with great sadness that on the morning of December 23rd, Douglas Reilly passed away. He is a noted author, contributor to the ASP.NET forums, and is passionately about his work. Most importantly he was a generous and kind man, and he will be missed. Rest in peace Doug.
Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 4 Comments
Tuesday, December 19, 2006 5:26 PM

Announcing VS 2005 SP1

I've been a bit out of the loop lately with a new job, moving, and wrestling the Manager of an appartment complex. However recently I discoved that Visual Studio 2005 Service Pack 1 has been released. Get it here:

UPDATE: Sorry guys the link I posted was for the Express Editions only. Here is where you can get them from Express, Standard, Pro, or Team

http://msdn.microsoft.com/vstudio/support/vs2005sp1/default.aspx

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 5 Comments
Thursday, November 30, 2006 7:52 PM

I bought a Zune

On a whim I bought a Zune. I needed a new Music Player. I didn't want an iPod because iPod's can't play any of my WMA music library. So the Zune seemed like the right place to go. Here is what I expect from a portable music player:

  1. Attach my Zune to the computer. Install drivers if need be.
  2. Copy files to device. Using Windows Media Player
  3. Play music.

Not that complicating, right? Here is how it really went:

  1. Attach Zune to 64-bit computer. Find out it doesn't work in a 64-bit computer. (It is not Vista compatible yet either)
  2. Attach Zune to Laptop using 32-bit XP.
  3. Install Drivers (that actually went well)
  4. Install Zune Player.
    What? I can't use Windows Media Player to sync my library? That is rediculous!  Instead I have to use a watered down version of Windows Media Player.
  5. Copy files over (that went quickly)

So I ran into a few bumps, no biggy. Here is where I get pissed off. The Zune can NOT play DRM protected music unless it was purchased from the Zune Market Place. Let me explain why that makes me angry.

A while back Microsoft Started a Program called PlayForSure. Basically it certifies that a device is capable of playing Windows Media Audio/Video. Included in that Certification, is DRM. So the Zune doesn't meet the PlayForSure logoing. What DRM music am I talking about? Music I bought from MSN Music . It is another example of Microsoft not supporting it's own products. It also cannot play music from URGE, which Microsoft built into Windows Media Player 11 and spent tons of money marketing during the beta releases of WMP 11.

What I ended up doing is burning all of my DRM protected albums to CD (All 35 of them) to a CD-RW, and re ripping them.

Though once I got past the kinks, I did like it. Great sound.

UPDATE: I played around with it a bit longer and I am really starting to warm up to this thing. It is a tad bulky compared to the iPod, but it is was worth sacrificing to me. One thing that I did find out that I though was great is this thing can play iTunes music provided it doesn't have DRM on it, like the XBox 360.

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 2 Comments
Friday, November 17, 2006 3:26 PM

New Job

I recently went into a job interview for Thycotic . (No coinicidence that's where Ryan works) and I am happy to say I got the job. I am very excited and eager to start working there, they have a lot of wonderful concepts such as Peer Programming. I'll be moving DC area in the middle of December.
Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 2 Comments
Friday, November 10, 2006 11:35 PM

ASP.NET Moderator

I was recently asked to join the ASP.NET forums moderation team. I accepted - of course - and am looking forward to helping the community.
Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 2 Comments
Tuesday, November 07, 2006 11:19 PM

Windows Media Player 11 RTM

About a week ago (as of November 7 th ) Windows Media Player 11 was finally released. I was excited about it because I couldn't use the Betas, they weren't designed for x64. So when RTM was announced, so was the x64 edition. Sweet. I had seen my roommate's laptop had it installed, and I could have installed it on my laptop, but my laptop is in Russian and I wanted to wait for the MUI editions to come out. So downloaded, installed. Installation went without a hitch. It migrated my library, all seemed to go well. I am dissappointed that even though there is a special x64 download for WMP 11, the large portion of it is still 32-bit running on WOW64. A couple of personal opinions on WMP 11.

Dislikes: I like the Classic Windows Shell. Windows 2000. Windows Media Player 11 has the Vista look, whether you want it or not. I prefer the old fashion way. I'm an ol' fashion person. I don't like that it is always black. Yeah you can change the tint of it - slightly. Oh well. Nothing that effects the performance of it. The UI doesn't respond as quickly as I would like it to if I ask it to do something intensive. I also wish it were pure x64.

Good stuff: I had issues where MP 10 wouldn't recognize my CD burner (though Windows Explorer would). Now it does. Excellent. It also supports Ripping CDs in the Professional Codec.

It also rolled out a new version of the Windows Media Codec: 9.2 and Windows Media Professional 10.

Overall I like it.

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 0 Comments
Monday, November 06, 2006 1:03 AM

Delta Airlines Suck

I am an avid flier. I fly all over the world, Belarus and Russia mostly. Those a pretty far away (about 6,500 miles for Belarus) so I rack up Frequent Flier Miles pretty quick. Well I decided to attend Dev Con with Ryan, so I got some airline tickets to Vegas using my FF miles.

So I go to the ticket counter after spending 30 minutes trying to find a parking spot in Long Term Parking. No tickets. No Tickets? no tickets. OK, I so I am delayed a day. I was getting there early, no problem, I will get there on time instead. My Frequent Flier miles are gone, but, no tickets. Time to head home. (Oh and pay my way out of the long term parking that I was in for 15 minutes. Angry

Time to make some calls. I give them my transaction ID, all that jazz, they said:

OK. Since you are using Frequent Flier Miles, it will take a day to process.

Translation : We don't value our top customers and we don't want to give free airplane tickets.

Why did this happen? They sold my seat to a paying customer, even though I have previously spent thousands of dollars flying with them.

So I got my Frequent Flier Miles back. Oh, but I can't get tickets now. They are booked. And I am not in the mood to fork out money for tickets that I deserve as a valued customer.

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 0 Comments
Saturday, November 04, 2006 3:49 AM

Microsoft Drops the ball with OneCare and x64

I was surprised when the press release for OneCare came out. Microsoft making an Anti virus Suite? Sounds interesting. And something I would probably be interested in. Microsoft made Windows, so why shouldn't the maker of Windows make good programs for Windows? When RTM was released, I downloaded a trial. But guess what. It wouldn't install. Windows Live OneCare is not x64 compatible.

Ouch.

Microsoft has been trying to push the x64 platform on developers and the program industry, and now they release a software suite that is not x64 compatible? What about when Vista is released? The Windows Vista logo program requires that software be x64 compatible for it to get the "designed to run on Windows Vista" logo on the box. Is Microsoft going to make a software suite that will fail it's own logo program?

I got an e-mail asking if I wanted to participate in the OneCare v1.5 Beta. I checked it out, thinking. "OK, they know the release of Vista is close. It has to be x64 compatible."

Nope. So far, the beta for 1.5 is not x64 compatible. Seems ironic to me.

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 1 Comments
Filed under:
Tuesday, October 31, 2006 4:11 PM

MVP Nomination

I recently found out I am nominated for MVP. I consider just the nomination itself an honor. Thank you Ryan for the support.
Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 3 Comments
Sunday, October 29, 2006 3:48 PM

A Persistent Application State

We all know that an application state lasts while the application is running, but if the AppDomain gets restarted, from something like a change in the web.config file or a recompile. What if we want an Application State that always persists? One that is never lost, even if the entire server is restarted? Well I set off to do exactly that, and here is what I got.

The first thing I had to do when deciding how this would work is how I would store the values for this state. Logically a SQL Server came to mind, so I had to build an underlying way of communicating with a SQL Server, and an HttpModule seemed like the best way to accomplish this. So I was going to use SQL Server for holding my values. The next task is how to store everything in the SQL Server. I came up with 3 fields. The first being the key, the second being the application name (that way if you have two applications using the same key names, they won't conflict) and the 3rd being the value. I decided to go with Binary Serialization for storing values, to the value field is VARBINARY(MAX). This way we can store anything in our Persistent Application State so long as the object is serializable. To keep performance up, it doesn't read and write from the SQL Server exclusively. It caches everything for reading, so when you get a value it is getting it from an underlying dictionary, and during an update it updates the cache and the SQL Server values. The only time a read is done on the SQL Server is when the Init() method is called on the HttpModule. A SQL Script for creating the table is included in the project.

Since we are using an HttpModule, the module must be correctly registered in the web.config file, which would look something like this:

                    
                  

The next thing I had to accomplish was making this thing configurable. The web.config file seemed like the best way to do this, so I made a quick ConfigurationSection class to handle the configuration. The configuration has 2 basic attributes. applicationName and connectionStringName . applicationName should be a string that uniquely identifies the application. The connectionStringName is the name of the connection string that should be used to connect to the SQL Server that is in the section. An example of the web.config is included in the project.

The last thing I had to deal with is how to make this accessable from the Page. To solve this, I created a BasePage that exposes a Dictionary that works exactly like the Application, and hooks into the Module. To use it, derrive all of your pages from the class KGJ.PersistentApplicationState.BasePage and set the web.config file to use that as the base as well. This will expose the Dictionary PersistentApplication. From there on, use it like the Application State, except they will always be there until you delete them. How to use it: Simply put the compiled DLL in your BIN folder.

As far as other Databases, this code is easily adoptable to an Oracle or MySql client. Eventually I will adopt it so that it works like a provider.

Download the source code and projects here: Persistent Application State

Feel free to leave comments and suggestions, there is always room for improvement.

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 0 Comments
Filed under:
Wednesday, October 25, 2006 4:55 PM

AJAX Beta 1

It appears that Microsoft has dropped the ball with Beta 1 of AJAX, more over it is riddled with bugs and quirks. Here are some known issues and some work arounds for Beta 1

Web Service Calls Issue
http://forums.asp.net/thread/1441680.aspx

Extenders in Templated Controls Issue
http://forums.asp.net/thread/1441672.aspx

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 0 Comments
Filed under:
Thursday, October 19, 2006 10:35 AM

Announcing: IE 7 RTM!

It's finally here. IE7 RTM has finally hit the spot. Download it here:

http://www.microsoft.com/windows/ie/downloads/default.mspx

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 0 Comments
Filed under:

A Fun Windows Form Application

Ever play around with the Text-To-Speech in Windows XP? I thought that was fun when XP first came out and I always made it say crazy stuff, especially during computer lab. Later as a developer I wanted to implement this into a Windows Application I was making, just for fun.

The Speech API (SAPI) is a COM library, and it is no secret to .NET Developers that .NET has excellent support for COM libraries. The sapi.dll can usually be found in C:\Program Files\Common Files\Microsoft Shared\Speech. Using the .NET SDK, we can easily make a managed assembly for this using the Type Library Import, tlbimp.exe. You can run it from the SDK Command prompt in the start menu. Using the command prompt we can generate the Managed Version of it, what I called sapi.net.dll using this in the .NET SDK Command Prompt:

C:\Program Files\Microsoft.NET\SDK\v2.0 64bit>tlbimp "C:\Program Files\Common Files\Microsoft Shared\Speech\sapi.dll" /out:C:\sapi.net.dll

The Type Library Mashaler won't be able to completely marshal it for you, but it will be able to do enough of it for us to get what we want. (Note that in my example I used the 64-bit platform, so your SDK path won't be the same). This will generate the Assembly we need for making a taking application.

So now we can use this assembly in a Windows Form Project, and all we have to do is add a reference for it.

The primary interface and class we will be using is SpVoice and SpVoiceClass, which were made by our type library importer. SpVoiceClass is what we will use to make our application talk. The method "Speak" accepts two arguements, the text to be spoken (as a string) and flags (as an int enumeration). Type Library Importer automatically generated a flag enumeration called SpeechVoiceSpeakFlags. The two I use in this application is SVSFIsNotXML and SVSFlagsAsync. SVSFlagsAsync is important so your thread won't lockup when you start speaking. Optionally, you can use your own worker thread, which is recommended since we don't want to be talking on the UI thread:

private SpVoiceClass voice = new SpVoiceClass ();

SpVoiceClass voice = new SpVoiceClass ();

ThreadPool . QueueUserWorkItem(( delegate ( object arg)
{
voice . Speak( "Hello!" , SpeechVoiceSpeakFlags . SVSFIsNotXML | SpeechVoiceSpeakFlags . SVSFlagsAsync);
}),
null );

this.voice is an instance of the SpVoiceClass class.

Assuming one has Office installed, you have extra voices. I got bored of Microsoft Sam so I wanted to use others voices, for which I created a helper method like this:

static List < DictionaryEntry > AvailableVoices
{
get
{
SpVoiceClass voice = new SpVoiceClass ();
List < DictionaryEntry > voices = new List < DictionaryEntry > ();
for ( int i = 0 ; i < voice . GetVoices( null , null ) . Count; i ++ )
voices
. Add( new System . Collections . DictionaryEntry (voice . GetVoices( null , null ) . Item(i) . GetDescription(System . Globalization . CultureInfo . CurrentCulture . LCID), voice . GetVoices( null , null ) . Item(i)));
return voices;
}
}

The reasoning for using a List filled with DictionaryEntry's is for databinding purposes, since the binding must implement the interface IList. This returns a List of DictionaryEntries, the dictionary key being the voices name, the value being the actual voice itself, which is the interface ISpObjectToken. So now we have a list of the voices installed on the machine.

The SpVoiceClass has a method called SetVoice which accepts an ISpObjectToken for setting the voice.

The SpVoice class can also allow you to save a WAV recording of the voice, just by changing around the output stream. I used a BackgroundWorker class to help me with this so I can do it on another thread.

The stream we will be using for this is SpFileStreamClass, which must exist on the same thread as the SpVoice class, so we need to pass it as an arguement in the RunWorkAsync method.

You can download the full sourcecode and run it for yourself here: Speech

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones | 1 Comments
Filed under: , ,
More Posts Next page »