C# How to hash a password

Sometimes you have to keep things simple. This will show you, how to hash a password (string) using MD5 or SHA-1 in C#.

First of all, put this in your source:

using System.Web.Security;

Next, create a static method that we can use anywhere in our solution:

public static string HashedPassword(string password)
{
   return FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5");
}

The FormsAuthentication class is the same, as used by the asp.net Login control. Replace md5 with "sha1" if you want a more safer hashing. Sha1 uses a 160-bit hash function which resembles the md5.

All you have to do now, is to use the new method, before saving the password to the database:

UserPassword = HashedPassword(myPasswordField);

UserPassword is the field name in your database and myPasswordField is the field name, containing the password that the user typed, when creating the user.

In your login method, you have to do almost the same. The user is typing a username and password, where the password is typed in clear text. Clear text can't be compared to the password that we've saved in the database, because it was MD5 hashed.

The trick here is to use our static method again:

if (HashedPassword(enteredPassword) == UserPassword)
  // Password was correct
else
  // Password was incorrect

enteredPassword is the field name, containing what ever the user was typing when trying to login. UserPassword is the field name, containg the users password from the database.

Remember

First of all, MD5 hashing is one way only, which means that it's not possible to "De-Hash" it again. Second, MD5 is not the safest way to save passwords in a none-readable way. But sha1 should be useful in most cases.

7. December 2010 21:45 by bbc | Comments (0) | Permalink

8-bit trip

I just found my old Commodore 64 from the back of the closet. It's 22 years old and still running.... I've decided to do a 4k demo - just for fun.

To get inspiration before stealing some 8-bit music, I found this youtube masterpiece. ENJOY IT!

29. September 2010 21:09 by bbc | Comments (0) | Permalink

24 hours has ended

My 2010 photo marathon has ended - 24 hours of finding interesting shots. And it was as tough as I expected and was not a "walk in the park". During the 24 hours I tried to sleep a few times, but with no luck. So 1 hour after deadline, I went to bed and took 3 hours of deep sleep before waking up again, in the middle of sunday afternoon.

But back to the photo marathon. I was much more satisfied with my resulting pictures than last year and guess that one year of photo marathon experience was helping me out this time. I used more time to think about all topics, before running out to look for random shots. On some topics I had to drop all plans and then go looking for random ideas. Actually I drove about 150 kilometers during the 24 hours.... So mabe my topics wasn't planned at all as I think? But one thing was planned and that was to use only primes for all 24 pictures. All my pictures were taken with Nikon 50mm 1.8 and Nikon 105mm macro lenses. They are both doing razor sharp pictures and I don't regret using these.

I can't show you my results yet, because it's not allowed to show them to public until 12th of september. So you have to wait to see my 24 shots. I have examined my pictures again after the photo marathon has ended and of course I'm not satisfied with all pictures, but I guess that I have 7 very good technical shots and 10-12 pictures that I'm very satisfied with. The rest is a result of stress, missing ideas and midnight crises and for sure I'm not the winner this year again, but I could have a few shots that could win one of the individual topic prizes.

And as mentioned earlier, I contributed to this photo marathon with a Windows program that read and copy a contestants pictures and validates them, accordingly to the photo marathon rules. Before the photo marathon started, I was awarded with an honor for contributing with this software and this was a huge surprise! And acutally the program worked - it copied, validated and created web-galleries of more than 6000 pictures without any problems. I haven't heard of any problems anyway Cool Maybe they will show up later? But hope not of course.

2nd of October will be the date of results and I cross my fingers that I can win a prize, but with more than 300 other amazing and good contestants I need to have luck. But lets see about that in October.

31. August 2010 06:49 by bbc | Comments (0) | Permalink

Photomarathon countdown

Today there's less than one week, until the 2010 photomarathon in Denmark begins. This year I'm more prepared than last year and it will be fun.

And this year, they will use my Windows program that I've coded to import photos and validate all photos with the photomarathon rules. It will be interesting to see if everything works as it's supposed too. I didn't hear anything from the organizers about test-failures, so I cross my fingers and hope for the best.

24. August 2010 06:57 by bbc | Comments (0) | Permalink

My flickr account

If you would like to see more pictures and in a better resolution, zoom into my flick account here:

http://www.flickr.com/photos/bbcdk/

18. August 2010 19:55 by bbc | Comments (0) | Permalink

Why you have to google yourself

I guess that we all are googling ourself now and then. Some people are more exposed than others and I'm not. But this time, I've found an article on the homepage for "Danmarks Radio" who is the Danish public service radio and TV channel, where they use one of my pictures.

http://www.dr.dk/Regioner/Nord/Nyheder/Aalborg/2010/04/07/145730.htm

I recall that I did send this picture to a competition some years ago. A good example, how important it is to read the terms for attending a competition and how they can use the picture in the future. For me it's ok. I'm not a PRO photographer and is just happy to see my pictures around.

So go google your self, maybe you will find something interesting Smile

 

12. August 2010 23:10 by bbc | Comments (0) | Permalink

I took the 1st price

Unfortunately it was back in 1996 and it was at the time, when i used all my money on cars..

I attended the yearly gathering for Peugeot geeks in Denmark and they had a lot different competitions going on that weekend. All competitors could vote and they voted my Peugeot 106 GTI as the best original.

I know it's nothing special, but it was funny to find this trophy back in the closet. By the way, this was the car:

Today I miss the car. It was fun, no weight and 131 hp.

6. August 2010 00:06 by bbc | Comments (0) | Permalink

Danish photomarathon 2010

I am now an official participant of the Danish photomarathon 2010 Smile  Last year i managed to go through all 24 hours, but this year I have a plan to win one of the 24 individual prices. Call me stupid or naive, but if I don't have a goal, I can't motivate my self to do it again.

From last year, I've learned a bit. This year I have a plan about my 24 pictures and it will not be 24 chaos chosen pictures without some kind of connection. It could be a technical connection or something completly different.

If you want to participate too, see the rules on www.fotomarathon.dk

FotoMarathon 2010

4. August 2010 03:40 by bbc | Comments (0) | Permalink

Welcome

Welcome to my blog. I hope that you will enjoy my postings and you are always welcome to contact me, if you have any questions. I know that my English skills are not perfect, but I hope that the language will make the blog more interesting for more people, compared to a Danish blog.

I will try to find a suitable gallery module for this blog, because showing my pictures in 500px width is not the best. Anybody with a nice gallery??

3. August 2010 04:44 by bbc | Comments (0) | Permalink

Back from Paris

Me and my family have just returned from a nice long trip to Paris / France. Two days in Disney with roller coaster rides "en massé". Not as exiting as my Chernobyl trip, but time with the family is a must.

 

Me and my daughter in front of the Eiffel tower. My 5th visit to Paris, but not the last. This city is just amazing.

20. July 2010 05:16 by bbc | Comments (0) | Permalink

About me

Me? My name is Brian and I was born in 1971. I live in Aalborg / Denmark with my family and has worked with IT since 1991, when I finished my education.

 

What do i do? I work as a .NET programmer and that is the perfect world for  me Cool

 

What about hobbies? I have so many different interests, when I don't go to work. I'm chairman of the board in Aalborg Billiard Club, which is one of the largest billiard clubs in Denmark. And then I do a lot photos and love to go around in abandoned places to find interesting things to shoot with my camera.

 

Why English? I decided to write everything in English, even that I'm not perfect to write the language. I hope you can understand my blog entries anyway and don't kill me for all the spelling mistakes... BTW. Comments are disabled because spammers just can't stop :-(