Hey I would love to know what you think while reading my posts. Please comment!.

Changing the Password length in Asp.Net 5 Identity

A while ago I wrote a blog post regarding MVC 3 Password Length DataAnnotation in order to easily change the length of the password required to register for an account within your website.

This blog post is about how you can easily manage your password password strength in an Asp.Net vNext project (Asp.Net 5) when using the Microsoft.AspNet.Identity framework.

If you create a new Asp.Net 5 Web Application in Visual Studio 15 you will see that it is set up to use Microsoft.AspNet.Identity for handling user Authentication.

By default it will come with a RegisterViewModel that has the Password property and various DataAttributes

[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }

Similar to my MVC 3 Password Length DataAnnotation post, the length of the password is controlled from within the Model, so if you want to change this length then you will have to edit code.


My Top 10 Dad Jokes

I have a bit of a reputation for sharing bad dad jokes. So I thought I would compile a list of my top 10 for you to enjoy!

In reverse order

10.

A lot of people cry when they cut onions. The trick is to not form an emotional bond.

9.

Sometimes I use words I don’t understand so I can sound more Photosynthesis.

8.

I cut my finger chopping cheese, but I think that I may have grater problems.

7.

What would you catch if you had sex with Harry Potter? Genital Hogwarts.

6.

My pet mouse Elvis died last night. He was caught in a trap.


Handy Git command reference

Handy Git command reference

Handy Git command reference

Handy Git command reference

Sooooo like a lot of developers out there, you probably have moments where you completely forget what git command you need to use for the correct job. There are hundreds even thousands of websites out there all with the same information, so I thought I would write another!

This is primarily just for my own reference though, so I have everything in one place that I can easily find without hunting through my many document locations.


Me right now bug fixing


Sharing an Asp.Net Machine Key for Authentication

In a recent project that I have been working on, one of the requirements was that we use our client’s Machine Key so that we can authenticate user’s passwords if their users had to login directly into our system. This was mainly to handle a situation where the main website would go down then users could open up our system directly and login.

So the client would send us the user details, username/password/passwordsalt and then they supplied us with the Machine Key that they are using in their various environments. The encryption which was being used was the standard out of the box asp.net Membership encryption, so in order to encrypt the typed in password against what is in the database, i used the following code:

public string EncryptPassword(string password, string passwordSalt)
{

    byte[] bytePass = Encoding.Unicode.GetBytes(password);
    byte[] byteSalt = Convert.FromBase64String(passwordSalt);
    byte[] byteResult = new byte[byteSalt.Length + bytePass.Length];

    Buffer.BlockCopy(byteSalt, 0, byteResult, 0, byteSalt.Length);
    Buffer.BlockCopy(bytePass, 0, byteResult, byteSalt.Length, bytePass.Length);

    HashAlgorithm ha = HashAlgorithm.Create("SHA1");
    return Convert.ToBase64String(ha.ComputeHash(byteResult));

}

While testing in a c# app this worked great, however when I then ported the code over to vb.net (yes our system is partially in vb.net), the generated encrypted password no longer matched.


Github Pages with Jekyll and Markdown

Static site generation with Jekyll for Github pages

Static site generation with Jekyll for Github pages

Github Pages with Jekyll and Markdown

I had originally planned on adding this post when I first launched my website on Github Pages, but for some strange reason the post sat in a half-written state and unpublished. It could have also been because I had never managed to get Jekyll running on Windows at that time! I have now though, so see below on how to get this up and running. :)

Github Pages

If you have never heard about Github pages before and are looking for somewhere to host your own personal blog, then I would suggest checking it out now. pages.github.com host static html websites using your own repository to manage the files. You get one site per GitHub account and unlimited project sites. Simply create a new repository named [username].github.io and you are away!


NuGet pack fails with exited with code 1

We had a very annoying issue in the office recently regarding building a NuGet package with a Post-build event command line. One of our developers had created a Utilities project which would be installed via our local NuGet store, and had added the Post-build event to create the NuGet package.

The Post-build command was pretty simple and worked. It is the command which is referenced on the nuget.org Creating and Publishing a Package website

$(SolutionDir).nuget\nuget.exe pack $(ProjectDir)$(ProjectFileName) -Prop Configuration=$(ConfigurationName)

Everything was working great on the original developer’s machine, also on another guys machine, but not on mine or the 4th developer’s. Both I and the other developer are on Windows 7, the other two guys are on Windows 8. The Windows 7 machines were getting the error:

The command "C:\Projects\SolutionFolder\.nuget\nuget.exe pack C:\Projects\SolucationFolder\ProjectFolder\project.csproj -Prop Configuration=Debug" exited with code 1.

DNX SDK version 'dnx-clr-win-x86.1.0.0-beta5' failed to install.

I have been playing around with Visual Studio 2015 preview for a while now (nothing hard core), so naturally I want to install the final version when it was released. Straight away I came across a couple little issues which made the install/startup not so simple.


Asp.Net vNext

Working with MVC Areas in Asp.Net vNext (MVC 6)

Working with MVC Areas in Asp.Net vNext (MVC 6)

Working with MVC Areas in Asp.Net vNext (MVC 6)

I have recently started to play around Visual Studio 2015 Preview and Asp.Net vNext. As usual, I jump into new stuff like this with the mindset of building projects the same way that I would have with other versions. So in this case, I was trying to build a MVC 6 website the same way that I would build a MVC ¾/5 website.

Straight away I wanted to add an Area to the project. In Visual Studio 2013, I would have right clicked on the MVC project, selected “Add” and then “Area”, typed in the name for the Area and then Visual Studio would scaffold this for me.


Stopping and Starting your Application Pool with Octopus Deploy

Depending on your Web Server set up, you might not be able to overwrite the Bin folder without some manually intervention. Usually it is because there is a process using files within the Bin folder and you will have to stop the application pool first.

Octopus will soon inform you if this is the case when deploying your package to the server, and will give you the error message:

One or more files in the directory may be locked by another process. You could use a PreDeploy.ps1 script to stop any processes that may be locking the file. Error details follow.


More posts...

Posts by Tags...

About Me

Tim James I'm Tim, a web applications developer from Glasgow, Scotland. Currently working for Kingfisher Systems Ltd, building bespoke systems within the Car Auction industry.

  • C#
  • VB.NET
  • ASP.NET
  • .NET MVC
  • Web API
  • Razor
  • HTML5
  • CSS3
  • jQuery
  • WCF
  • SQL
  • knockout.js
  • Angularjs
  • AJAX
  • APIs
  • SignalR
Why not follow me on twitter? Follow me on Twitter