Password Protected Extension

26. August 2009 4:04 PM

Back to few days ago, a friend of mine who also using .NET BlogEngine was asking me about how to modify the code to make it support password protected post/page.

After I look into details about how am I going to kick start... and I found the best implementation is writing an 'Extension'. That how the 'PasswordProtected' extension was borned! See the sample post here!

Before you can enjoy the password protection features, you are require to defined more roles besides both the existing 'Administrators' and 'Editors' in the \App_Data\roles.xml data file as show in the screen shot below,

Note, after you have updated the roles.xml, you are require to restart the IIS before you can see the new defined role appear on the users screen. Then, you are begin to create more users under any others roles other then 'Administrators' and 'Editors'. As the best practice is using email address as the login ID, and further defined the nickname under the respective profile, so a correct nickname will be display on the comments instead the login ID (email address).

Next is download this extension and upload to your respective .NET BlogEngine folders.

  1.   Copy the 'PasswordProtected.cs' source fiel to '\\blog\App_Code\Extensions' folder.
  2.   Copy the 'protected.png' image file to '\\pics' folder (you may change this image).

 

Last thing you need to know is the syntax... a syntax that make your post/page become password protected!

  [protected:on|off;roles:role1,role2,role3]

Below is some of the self explain combination,

  • Turn the password protection off. 
      [protected:off]
  • Sample syntax for password protection enabled and only limit to all users with under role of 'role2'.
      [protected:on;roles:role2]
  • Another sample syntax with password protection enabled and limit to all users with under role of 'role1' and 'role3'.
      [protected:on;roles:role1,role3]


Note
, both 'Administrators' and 'Editors' role will overwrite the defined role in the above syntax.


 

 PasswordProtected.v1.0.826.1.zip (37.48 kb)

BlogEngine.NET ,

Password Protected Demo Post

26. August 2009 1:44 PM

This is a protected post, you are require to login prior read this post.

BlogEngine.NET ,

Implement Your Own Ip2Location Information Services

20. August 2009 5:34 PM

Nowaday every blogger also have free visitors map on thier side bar that power by the following providers,

 

Last week, I decided to implement my own IP to location information services for my blog, and I keep sourcing the free Geo IP information database. At first, I found the ipligence community free edition. Which only offers,

  •    Region Code/Name.
  •    Country Code/Name.

 

Later, I found a better free database from IPInfoDB, which offer a much more comprehensive IP Geo information. As it cover the following informations,

  •    Country Code/Name.
  •    Region Code/Name.
  •    City Name.
  •    Zip Code.
  •    GPS Latitude/Longitude.
  •    GMT Offset.
  •    DST Offset.

 

While the entire database is about 95MB (3,486,705 records), which are will best fit into the normal webhosting offer MySQL database size limit (100MB/each database). Another advantage of the IPInfoDB database is they will have a new update on every first week of each month.

Since, I have implemented and I would like to post it up and share with other who need it. Below is the only one SQL query statement used to retrieve the data.

   1:  SELECT l.country_code, c.name AS country_name, l.region_code, r.name as region_name, 
   2:         l.city, l.zipcode, l.latitude, l.longitude, l.gmtoffset, l.dstoffset
   3:  FROM ip_group_city AS i
   4:      LEFT JOIN locations AS l ON i.location = l.id
   5:      LEFT JOIN iso3166_countries AS c ON l.country_code = c.code
   6:      LEFT JOIN fips_regions AS r ON l.region_code = r.code AND l.country_code = r.country_code
   7:  WHERE i.ip_start <= INET_ATON('76.238.227.61')
   8:  ORDER BY i.ip_start DESC LIMIT 1;
 

The result will be further formated into XML show below,

   1:  <LookUp>
   2:    <Item>
   3:      <IP>76.238.227.61</IP> 
   4:      <CountryCode>US</CountryCode> 
   5:      <CountryName>United States</CountryName> 
   6:      <RegionCode>06</RegionCode> 
   7:      <RegionName>California</RegionName> 
   8:      <City>Vista</City> 
   9:      <ZipCode>92081</ZipCode> 
  10:      <Latitude>33.2007</Latitude> 
  11:      <Longitude>-117.226</Longitude> 
  12:      <GmtOffset>-8</GmtOffset> 
  13:      <DstOffset>-7</DstOffset> 
  14:    </Item>
  15:  </LookUp>

Please download the free database from IPInfoDB while you downloading this sample project (Ip2Location.zip).

 

Ip2Location.zip (20.92 kb)

 

Services , ,