Category Archives: Uncategorized

Encrypt Your Entire Boot Disk

Share

This is another entry in my list of articles on encrypting your entire digital life from end to end.  Click here for the lead article.  This article is about encrypting your entire boot disk on your server, desktop, or laptop computer.  I’ll be giving specific instructions for Windows, but Mac & Linux steps are similar.  Note that encrypting your boot drive is performed differently than encrypting non boot drives (which I’ll also cover in a separate article).  These instructions are using free, open source software that’s NOT from Microsoft.

Short (VERY short version)

    1. Install encryption software.
    2. Backup boot drive (no, seriously!  DO THIS!)
    3. Select boot volume.
    4. Provide passphrase.
    5. Reboot.
    6. Enter passphrase on boot prompt.
    7. Wait for boot.
    8. Encrypt volume.

The rest of this shows you the details of those steps.

Note the following trade-offs to encrypting your boot drive:

  1. When powering on or rebooting, your PC will stop until you enter your encryption passphrase.  This means you can’t reboot your PC remotely.  Someone has to physically be there.
  2. After typing in your passphrase, there will be a delay.  My PC takes 48 seconds that it didn’t take before.

Let’s begin

  1. Download and Install VeraCrypt from https://veracrypt.codeplex.com/releases/view/616110
  2. Open the “System” menu and choose “Encrypt System Partition/Drive”.
    1. image
  3. Follow the directions in the software.
  4. After you’ve answered all the prompts in the software, it will require you to reboot.  During boot, BEFORE Windows boots, you’ll be prompted to enter your passphrase.  Go ahead and enter it and hit [Enter].
  5. You’ll then be prompted for “PIM”.  Honestly, I have no idea what this is.  I just left it blank and hit [Enter].  All is good.
  6. Your PC will work on decrypting for a while.  My Quad-Core i5-4690K CPU @ 3.5Ghz takes about 48 seconds here.  Your mileage may vary depending on the speed of your CPU.
  7. Once it’s done there, Windows will boot.  Go ahead and log in.
  8. You still haven’t actually encrypted your disk yet.  You just got the VeraCrypt bootloader installed.  Shortly after you log in, VeraCrypt will automatically open and walk you through actually encrypting your disk.  That will be the final step.

DO NOT FORGET YOUR PASSPHRASE!!!!!

After that, you’re all done.  Now, every time you reboot, you’ll be prompted for your passphrase SO DON’T YOU DARE FORGET IT!  Seriously!  If you forget your passphrase, there’s NO WAY to recover it.  That’s it.  It’s done.  The data on your boot drive will be gone forever.  You’ll have to reformat your drive, install a fresh copy of Windows, and start all over OR pull out the drive and set it aside, hoping you’ll remember some day.  I cannot stress this enough.  You CANNOT forget your passphrase!  I recommend storing a HINT of your passphrase in an ENCRYPTED password management tool, like LastPass.  I use the “secure notes” feature to store mine.

Your drive is now much more secure.

What you NEED to know about Windows 8 and 10 disk encryption

And by “Windows 8 and 10 disk encryption”, I mean the built-in encryption capabilities of Windows.  I’m NOT talking about what we just did above with a third party product called VeraCrypt…

  • If you install Windows 8 or 10 on your own PC, then log into your Microsoft account, at that time, your DECRYPTION KEYS are UPLOADED to Microsoft servers!!!  Yes!  Without asking!
  • If you buy a PC with Windows 8 or 10 already on it, your decryption keys are ALREADY uploaded to Microsoft servers.
  • You can request that Microsoft delete your decryption key, but it’s already too late.  Once your decryption key leaves your hands, you can no longer trust that it’s secure.
  • To fix this, you’ll need to RE-Encrypt your disk, which requries generating a NEW key, then NEVER log into Windows with your Microsoft account.  Just… DON’T!  But DO create a LOCAL user account and use that from now on.

Thank you for sharing this article.  See this image?

image

You’ll find actual working versions of them at the top and bottom of this article. Please click the appropriate buttons in it to let your friends know about this article.

Share

Encrypting Your Cloud Storage

Share

image

This is the sixth entry in my “Encrypt All The Things!” series.

Let’s face it.  Cloud storage SUX!  Why?  Because all of the most popular cloud storage services do NOT provide end to end encryption.  Oh sure, you’re files travel over an https connection from your PC to their server, but your files are not encrypted with a public key from a private key that only YOU have access too.  Sure, the cloud storage providers may encrypt your files (with THEIR keys) AFTER they receive your upload and before they store them on their own drives.

BUT!

THEY have access to the contents of your files.  They can see the file names in clear text.  They have access to the entire contents.  THEY own the encryption keys on their end and you sent them your files without encrypting them first.  Therefore, you are NOT in control of your data.  If that cloud service gets hacked or if there’s a bad employee, or they get subpoena’d, other people can (and likely WILL) gain access to your personal data.  It’s simply NOT protected.

There’s only ONE option

When it comes to cloud storage, you have only one option for realistic security.  That is, your files MUST be encrypted ON YOUR END before they’re sent over the wire to the cloud storage provider and that encryption on your end MUST be done with your public key and your private key MUST be a key that ONLY YOU have access to.  It should exist ONLY on your own PC or phone.  PERIOD.  There are no if, ands, or buts about it.  This is called “zero knowledge” encryption.

Please see “Understand Encryption” on a discussion of public/private keys.  It’s kind of critical to your understanding of how to judge whether a cloud storage service is doing it right.

Zero Knowledge

Spideroak.com has this to say about zero knowledge encryption:

“Zero Knowledge means we know nothing about the encrypted data you store on our servers. This unique design means nothing leaves your computer until after it is encrypted and is never decrypted until it is unlocked with your password on your computer. It’s not just “end to end encryption;” it’s a Zero Knowledge System.”

Spideroak.com, by the way, is a cloud drive service provider.  Though, there are some critiques of the way they password protect your local key on your own PC, it is far more secure than Google Drive, Microsoft One Drive, Amazon cloud storage, DropBox, Box.Net, etc…

Another one with zero knowledge is Mega.co.nz.  This cloud storage provider was created by the infomous Kim DotCom who’s wanted by the United States government for hosting a similar service for copyright pirates.  So, some reasonable questions have arisen as to the true privacy of this site.  And recently Kim DotCom has come out and said he’s no longer affiliated with Mega and that you shouldn’t trust it, that it’s not safe (but can you trust HIM?)

Anyway, the point is, you need to either encrypt your own files BEFORE uploading them to a cloud service or use a cloud service that does it for you (ON YOUR END!).

Home Brew

Alternatively, you can do it yourself by manually encrypting your Individual Files then upload the encrypted files to any cloud storage provider you want.  It’s a bit of a hassle, but it will provide you actual protection.  You should note that if you upload your encrypted files, but keep the file names, a LOT can be known about what you’re storing.  Best to zip up the file first (storing the name in the zip file), giving the zip file an arcane name, like the date and time it was zipped, encrypt the zip file (not with the weak ass encrypting provided in the zip products, but with how I describe to encrypt Individual Files), THEN upload it.

Conclusion

    1. Save yourself some headaches and use only “zero knowledge” cloud services and thoroughly research what others have to say about their encryption.
    2. Hide your meta-data (file names, folder names, folder structures, etc…) if you’re going to home-brew it.

Do you have any experience with encrypted cloud storage?  Please share your experience in the comments.

Thank you for sharing this article.  See this image?

image

You’ll find actual working versions of them at the top and bottom of this article. Please click the appropriate buttons in it to let your friends know about this article.

Share

Stick it to the NSA: How to Encrypt your WebMail

Share

If you access your email from your desktop web browser, then follow these instructions to get email encryption working.  This is an initial draft.  I’ll expand some of the steps very soon.

  1. Install the Google Chrome  or Firefox browser if you haven’t already and install the extension named “Mailvelope” from https://www.mailvelope.com
  2. Once installed, there’ll be a new lock icon on the top right of your browser.  Click it and a menu opens.  Choose “options”.
  3. If you haven’t, at some time in the past, already created a private and public key pair, you’ll need to do that now.  If you don’t know what I’m talking about, you haven’t and you’ll need to do it now.  Click “Generate Key”.
  4. Once generated, it’s critical that you back up your private key, encrypted, to a place that no one can get it and that will last longer than your current hard drive and PC.  If you lose it, you’ll NEVER be able to read ANYTHING you’ve encrypted with your keys!  Install LastPass.com, create a secret note, and put your private key in there for long term, encrypted, safe storage.  Mark the note as “must reprompt for password”.  NEVER, EVER give anyone your private key.  NEVER send it unencrypted over the internet.  NEVER email it in an unencrypted e-mail message!  NEVER send it unencrypted over a wireless network, especially an open or public one.
  5. No one can send you encrypted e-mail unless they have your PUBLIC key.  Publish your PUBLIC key to a key server.  DO NOT PUBLISH YOUR PRIVATE KEY!!!!!!!! EVER!!!

Now, when you use GMail or most any of the other popular, free e-mail services in a  desktop browser, you can send and receive encrypted e-mail.  NOTE!  Just because you have the ability to send and receive encrypted e-mail does NOT mean that all your e-mail will be encrypted.  You MUST understand the following:

  1. Nothing you did here encrypted any of your old email.
  2. New email that comes in will usually be in clear text (NOT encrypted).
  3. When you start a new email message, Mailvelope will recognize this and provide you an icon, overlayed in your new email window.  Click it to write your email, then click “encrypt” to encrypt the email.
  4. You CANNOT send encrypted email to people that aren’t already set up, like you are, to send and receive encrypted email.
  5. You can’t send encrypted e-mail to anyone from whom you’ve not acquired their public key.
  6. You acquire public keys by searching on a key server.  MIT’s key server is here:. https://pgp.mit.edu
  7. Use the Mailvelope menu to import the public key of each individual with whom you wish to send encrypted email to.  You’ll find that most people have NOT registered a public key, so  you cannot participate in encrypted email with them.
  8. Once you encrypt and send an email message, you won’t be able to read it from your sent box.  It’ll be there, but encrypted with THEIR public key.  Only THEIR private key can decrypt it.  So, send it to both them AND yourself, THEN you can read it.
  9. Encrypted email is unreadable even by Google’s servers, which means you CANNOT use the Google email search feature for words in encrypted mail.
  10. ONLY the BODY of the email is encrypted, not the subject line, not the TO address, not your FROM address, not any part of the headers.

Things to note about HOW the keys work:

  1. When you generate keys, you only do it once, unless you have multiple email addresses.  In which case, generate a key pair for each of your email addresses you wish to send and receive encrypted email for.
  2. Keys are  created in pairs:  One is public.  The other is private.
  3. Feel free to give away your public key to ANYONE, ANYWHERE, ANYTIME.  Shout it from the mountain tops.
  4. Protect your private key with your life.  Well, don’t die for it, but it’s critical you protect it!  If anyone EVER acquires it, they can read EVERYTHING you’ve ever encrypted with your public key!
  5. Your public and private keys are intimately, mathematically connected.  Anything encrypted with your public key can ONLY be decrypted with your private key and  vice versa.
  6. Nothing is safe if you encrypt it with your private key, because everyone has your public key and can easily decrypt it.  A side benefit is you can do this to prove YOU are the one that created the message.  This is called “digitally signing” your document.
  7. If you want to encrypt something that ONLY YOU can decrypt, encrypt it with your PUBLIC key.  Decrypt it with your PRIVATE key.
Share

What is Bitcoin?

Share

Production Of Bitcoins By Mike Caldwell of Casascius

BitCoin, also known as a “Cryptocurrency” is not as complex to understand as one might think.  To understand BitCoin, let’s first review what “real” money is (or what it’s supposed to be):

In the United States, “Real” money is paper and coins, manufactured by the Federal Reserve.  It has no real value on it’s own.  It’s a low cost representation of gold.  At least, that’s what it used to be.  When it’s backed by a real world and limited resources that can’t be duplicated, it can represent real value because the item behind the money (the gold) is rare, limited, and can’t be duplicated.  Instead of exchanging actual gold for goods and services, we exchange the paper and coin representations of that gold.

So, what about BitCoin?

Now, think of this:  You have a set of incredibly complex mathematical formulas that you want to calculate the answers to.  The problem is that it takes a high speed computer days (or more) of crunching numbers 24/7 before it can find an answer to just ONE of those formulas.  That’s what a BitCoin is!  It’s an answer to one of those complex numbers.  You can’t duplicate it.  You can’t fake it.  You have to mine it, just like you have to mine gold.  But instead of picks and axes, you use CPUs.  It’s still a LOT of work to “find” the “nuggets” of answers.  Additionally, there are a limited number of answers… about 21 million.  So, once the last one is mined, that’s it.  No more manufacturing of more BitCoins.

Now, as you know, gold is represented by paper and low cost metal coins.  How is BitCoin represented?  Well, it’s NOT represented with tangible things you can hold in your hand.  It’s just numbers… the numbers that represent the answers to the formulas.  You CAN print them out on paper and store them under  your mattress, if you like, so in a way, you CAN make paper representations of it.  But, you CANNOT counterfeit it.  When you buy something with BitCoin, you don’t just hand someone a printed piece of paper with a bunch of numbers on it.  I mean, you COULD, but that, by itself, won’t fly.  You give them the numbers (either electronically or on paper) and they then run the numbers through one of many transaction processors (actually, I think it goes through many).  The processors are servers run by many people around the world.  They VALIDATE that those numbers are, in fact, an actual BitCoin… an actual answer to one of the 21 million formulas.  Once validated, the person you’re buying form can accept it, then give you the goods or services you’re wanting to buy.

In short:

A BitCoin is a limited and non counterfeit-able asset, just like gold.  But instead of a tangible asset, it’s an answer to a complex math problem.  Your “money” in BitCoin is usually kept in digital form and is validated on each transaction as being real.

What is your use of BitCoin?

View Results

Loading ... Loading ...
Share

Best Android Apps to start off 2013 (Shopping)

Share

imageAll these apps are FREE!  This article is one of a series of articles about the best Android apps available as of the beginning of 2013.  Click here for the main article that includes links to this article and links to all the other categories of “The Best Of” apps for beginning 2013.  Let’s get started with the Shopping category, which lists the best shopping related apps available at the ending of 2012 and beginning of 2013.

 

Amazon2012-12-31 18.41.13

The Amazon app is a native front end to the Amazon online store (not the app store).  This provides most of the features in the web site (if not all of them… I’ve, by no means, researched each and every feature of this massive web site).

This app is useful for obvious reasons in addition to the fact that you can be browsing in a brick and mortar store, like Wal-Mart, pick up an actual item off the shelf and scan its barcode into this app and it’ll tell you what you can get it for on Amazon.

I won’t go into extreme detail of what this app does.  If you’re familiar with Amazon.com, you already have a good idea.  You can, of course, track your Amazon.com orders with this app too.

2012-12-31 18.58.17Amazon App Store

One of the great things about Android is that you’re NOT locked into just ONE app store, like you are with iOS and Windows Phone.  You don’t have to root or jailbrake your Android phone to install another app store.  It’s perfectly legitimate to do so on Android.

The Amazon Android App Store is a direct competitor to the Google Play app store that’s pre-installed on almost every Android device made (with the exception of the really cheap and crappy Chinese Android products).

To Install It:

Go to Settings –> Security –> Unknown Sources

and make sure it’s checked.

Then go to this URL to download it to your phone (or Google search for “Amazon App Store”).

image

Amazon Price Check2012-12-31 18.52.59

This app lets you scan barcodes while in a real store and compare the prices to Amazon… Not sure why this is a different app from the Amazon app.

 

2012-12-31 18.42.00Ebay

This is a nicer and more responsive native app than trying to use the ebay website from your mobile browser.  If you’re familiar with ebay, you already know what you can do with this app.  If not, just look at this screen shot and that should pretty much tell you what you need to know.

Best Buy2012-12-31 18.43.472012-12-31 18.44.45

This is a front end to the Best Buy web site and is very useful when you’re in a physical Best Buy store.  If you’ll notice, most products have a ticket on the shelf with a price, a small description, and a 2D QR bar code.  Scan it with this app and you’ll get the full details of the product.

You can also check the balance of your Best Buy gift cards by simply taking a picture of the back of your gift card.

If you’re a RewardsZone member (and if not, WHY NOT?), you can check on your RewardZone points and even display your RewardZone points on your phone to the cashier at checkout to redeem your points, instead of printing them out at home and bringing them in.  You’ll save ink, paper, time, frustration, and money… an the “green” Nazis will sprinkle their happy happy fairy dust on you.

2012-12-31 18.45.502012-12-31 18.45.20Game Stop

The GameStop app is a native front end to the GameStop web site, with the addition of letting you “check in” to GameStop stores when you arrive to receive some PowerUp points.  You can keep track of your PowerUp points with the app too.  And, of course, like all store apps, you can search and browse their product selection.

FedEx2012-12-31 18.47.032012-12-31 18.46.51

The FedEx app is highly useful when you’re tracking a packing you’ve either sent or are expecting to receive (such as one you ordered with say, the Amazon app).  The screen shots to the right pretty much sum up what this app does.  It’s short and simple… It does the things you expect and nothing fancy.

2012-12-31 18.42.292012-12-31 18.42.35UPS

The UPS app is similar to the FedEx app.  It does the same thing, except for UPS shipments.  No surprises here.

 

QR Droid2012-12-31 19.52.382012-12-31 20.14.05 & Barcode Scanner

Both apps “QR Droid” and “Barcode Scanner” let you scan those 2D barcodes you’re seeing everywhere.  They usually represent a URL and it’s extremely convenient to scan them in places like BestBuy on product tags on the shelves or on movie posters or even on web sites on your desktop computer to load up the URL on your phone.  Installing QR Droid also gives you the ability to create your OWN QR Codes.  For example, you can send a contact from your contacts to it and it’ll display as a QR code on your screen.  Someone else can scan your screen with their phone and receive your contact.  If you’re on a web page, you can share the web page to the app and it’ll produce a QR Code with the URL encoded in it.  You can save it and e-mail it or publish it on your website, or show it on your screen to let someone else scan it.  But, since we’re in the “Shopping” apps category here, you can use it to scan 2D QR Codes in stores to get more information on the products and to even compare prices.

2012-12-31 19.07.39Kroger

The Kroger app is a master app for all the stores shown in the screen shot:

  • Kroger
  • Baker’s
  • CityMarket
  • Dillons
  • Food4Less
  • Food4Less Fremont
  • Foods Co
  • Fred Meyer
  • Fry’s
  • Gerbes
  • JayC Food Stores
  • King Suupers
  • Owen’s
  • Pay Less Super Markets
  • QFC Quality Food Centers
  • Ralphs
  • Smith’s

Kroger is the parent company for all these grocery stores.  This app works with all of them.  If you have a customer loyalty card at any of these stores (and if you don’t, WHY NOT?) they all work at all those stores.  This app will let you browse coupons and add them to your card.  When you check out, if you’ve put any of those products in your cart, when you swipe your card at the register, all those coupons are applied.  You can check your fuel points too and see the weekly ads.  This is a MUST HAVE app if you shop at any of these grocery stores.

CraigsNotifica

That’s not a typo.  That’s actually what it’s called.  This is an unofficial Craig’s List app.  With it, you can search Craig’s List and receive notifications based on your searches, add items to your favorites and even post ads.  There are a million Craig’s List apps.  Just find one that you like and use it.  This one works perfectly fine.

Google Shopper2012-12-31 20.37.39

Google Shopper integrates with “Barcode Scanner” (reviewed above).  Scan any barcode and this app will find multiple sources for that product.  This is probably the best way to find the best price on anything.  Use this when shopping in any physical store to decide whether or not it’s worth buying that product in your hands now, or somewhere else.

You Chime In

What are some of YOUR favorite apps in this category?  Let us know in the comments below.

Conclusion

This completes my list of “Best” shopping apps available to start off 2013.  There are, of course, other shopping of apps and this is, by no means, a comprehensive list.  Some of these are the apps in this category that I use on a daily basis and install on a new phone or tablet as soon as I get it.

Click here to follow me on Google+.

Follow me on Twitter @CSharpner.

See these images?

imageimage

You’ll find an actual working versions of them at the top and bottom of this article. Please click the appropriate buttons in it to let your friends know about this article.

Check back later for updates too!

 

Share

Poll: What do you do for privacy concerning your webcam(s)?

Share

Considering that there are various types of spyware floating around that literally spy on you using your own webcam, do you take any precautions to protect your privacy?

Do you cover up or disconnect your webcam on your PC/mobile to protect your privacy just in case some spyware found its way onto your machine to send images of you back to the hacker(s)?

View Results

Loading ... Loading ...
Share

How to use untyped Session Variables

Share

Session variables are helpful, of course, but they have many drawbacks, including having to access them by name in a string (no intellisense, no compile time error checking), they’re untyped, so you have to cast them, and it’s easy to accidentally use the same name from different pages for different purposes and overwrite their contents, creating odd runtime behavior that’s nearly impossible to track down.  (BTW, this works for application variables too, of course).

Click here to follow me on Google+.

In this article, I’ll provide simple techniques to completely eliminate ALL of these problems.

Accidental reuse of the same name

Take this session variable as an example:

Session["SomeEventTime"] = DateTime.Now;

Imagine two developers (or even ONE developer… I’ve done this myself) working on 2 pages of the same app at the same time.  The app may have timestamps that it needs to track.  It’s not uncommon for 2 programmers who work together to come up with the same name for their own session variables.  When a user runs the app and uses one page that sets the variable, then visits the other page, that resets it, then any code that depended on the first one will behave poorly.

Typos of the name

Take this example:

Session["SomeEventTime"] = DateTime.Now;
this.EventTimeLabel.text = ((DateTime)Session["SomEvenTime"]).ToString();

Notice the error?  On the second line, the “e” in “Some” is missing and the “t” in “Event” is missing.  The compiler won’t catch this.  It’ll only be caught at run time and likely by the customer, which is embarrassing and gives both you and your team a negative image and increases the cost to the customer because you’ve got to go back in and fix it.

Notice also that you don’t get intellisense with session variable names like you do with components and other variables?  You just have to know that the session variable exists, what its name is, and what type of data is stored in it.  There’s no catalog or anything at all to know what session variables are used.  You just have to be extremely diligent, search the source for use before you make up a new one, do this 100% of the time, and hope that the other developers on your team are also doing this, diligently, 100% of the time.  Chances of that happening?  Nearly zero.

Untyped

Notice also that the compiler has no idea what type of object is stored in the session variable?  In C#, you have to cast it, which means you have to just “know” what’s in there, and if you’re wrong, the compiler won’t know… It’ll just accept it, compile it, and then it’ll crash at run time.  VB.Net doesn’t require you to cast it, but same runtime problem.  If you assign it to a variable of the wrong type, the compiler won’t catch it, will compile it, and your customers will find the runtime error.

Solutions!

Here’s how to resolve each of these problems:

Accidental reuse of the same name

This one’s easy, but apparently not obvious to most programmers until it’s pointed out to them.  Let’s see if you can figure it out before I tell it to you.  Think of databases.  How do you guarantee that a record identifier is 100% unique and never used anywhere else?

A GUID, of course!

image

So, give your session variable names a GUID.  Each session variable gets a different GUID.  Don’t be so judgmental just yet.  Yes, of course, they’re impossible to remember and to type, but I’ll cover that in a moment.  For now, I’m solving the problem of accidental reuse.  You KNOW no one else is going to use the same GUID.  So, your SomeEventTime session variable now looks like this:

Session["E4D1DE1A-ECC9-45FF-8B78-C5CD16803CFF"]

Now, to solve THREE more problems at once… one of them that we just introduced:

Gaining intellisense, giving it a usable name, and giving it a type

Wrap your session variable up in a property.

 public DateTime SomeEventTime 
{
get{return (DateTime)Session["E4D1DE1A-ECC9-45FF-8B78-C5CD16803CFF"];}
set{Session["E4D1DE1A-ECC9-45FF-8B78-C5CD16803CFF"] = value;}
}

Now, when you use your session variable, you reference the property name.  This gives you intellisense, fully typed session variables, and eliminates any concern of the internal session variable name being too hard to remember and type out.

You’ve just gained another benefit by making it a property:  Triggers!

Now that it’s wrapped up in a property, you can add special code during the assignment or during the reading of the variable.

Scope

One last thing to consider:  Scope.

Where do you create the property wrapper?  In the page?  Do you make it private? Public?  Do you put it in Global.asax?  I’ll leave that up to you to judge on a per case bases.  It might be the topic of another article here too.

What have you done?

You’ve eliminated every problem you have with session variables and gained:

  1. Type Safety.
  2. Intellisense.
  3. Compile time name checking.
  4. Triggers on setting and reading.
  5. Scope.
  6. Prevention of accidental reuse of the same name.

You’ve lost:

  1. Embarrasing runtime bugs.
  2. Wasted time looking for hard to find logic problems caused by two different parts of the code using the same name for what was believed to be different session variables.

See this image?

image_thumb26

You’ll find an actual working version of it at the bottom of this article. Please click the appropriate buttons in it to let your friends know about this article.

Check back later for updates too!

Click here to follow me on Google+.

Share

Accessing form UI elements in your ASP.NET code-behind

Share

I can’t believe that in 2011, when .Net has been around over 8 years and is in version 4.0 now (It’s 6th release, BTW (1.0, 1.1, 2.0, 3.0, 3.5, 4.0)), that people are still coding like this to access form elements:

 <input id="username" name="username" type="text">
<input id="password" name="password" type="password">

 string userName = Request.Form["username"];
string passWord = Request.Form["password"];

if(userName.IndexOf("@") > 0)
{
//do this
}
else
{
//do that
}

Click here to follow me on Google+.

That may have been necessary back in the old classic asp days, but there’s a way to do it that’s fully object oriented AND compile-time checked (as well as IDE editing time checked too!):

First, I wouldn’t use HTML elements, I’d use serverside objects, like this:

 <asp:TextBox ID="UserNameTextBox" runat="server">asp:TextBox>
<asp:TextBox ID="PassWordTextBox" runat="server" type="password">asp:TextBox>
 

(side note: Give objects names that say what they are, such as appending “TextBox” to TextBox objects, and put it at the end, so that it reads like you speak.)

But, if you insist on using HTML elements, add runat=”server” to them.  That way, the code-behind can have access to them as objects.


 <input id="UserNameInput" runat="server" type="text">
<input id="PassWordInput" runat="server" type="password">

 if(this.UserNameTextBox.Text.Contains("@"))
{
//(yes, I realize I ref’d UserNametTextBox
        //and not UserNameInput… Look at the code further up…)
}
else
{
//do that
}

The benefits of this are many-fold:

  1. Server-side objects have lots of extra capability since they’re fully object oriented objects.
  2. Adding runat=”server” to any element (including plain old HTML elements) makes them actual objects, accessible from your code-behind.
  3. While in the code-behind, you can type this. (or me. in VB.Net), as soon as you type the period, you’ll get intellisense popping up listing your GUI elements.
  4. Intellisense prevents typos.
  5. Since you’re referencing actual objects, the IDE will detect whether you have a typo and put the red squiggles underneath it in addition to adding an entry to your errors list in your errors view.
  6. The compiler will catch any typos or references to objects that don’t exist.
  7. You’ll catch errors before you publish your code, preventing your customers from finding the bugs, making you look bad.
  8. Since you’re catching bugs earlier, you’ll spend less time fixing your bugs that your customer finds, saving your customer money and embarrassment.

See this image?

image_thumb26

You’ll find an actual working version of it at the bottom of this article. Please click the appropriate buttons in it to let your friends know about this article.

Check back later for updates too!

Click here to follow me on Google+.

Share

Relativity for Everyone: Part II, Time and Length are Relative

Share

In part I, I talked about the constancy of the speed of light. If you haven’t read that yet, it’s required reading before continuing here. There are terms and symbols used here that were already explained in Part I.

Relativity for Everyone:  Part I:  The Speed of Light NEVER Changes!

By now, you should have allowed the post about the constancy of the speed of light to simmer for about a day and you’ve almost certainly rejected it and gotten mad at the very thought of it if you’ve also been discovering what appear to be massive logic problems with it. If so, GOOD! That means you’ve been thinking about it and you’re thinking appropriately.

Click here to follow me on Google+.

Now, we’re going to establish that there’s no such thing as an absolute coordinate system.  In other words, if you try to declare some point is space as x,y,z and it’s always that point and that point is always in the same place in space, you’ll find that has no meaning.  It makes no logical sense.  To give a coordinate, it has to be relative to some object.  Let me explain…

Suppose you’re on a long train and suppose that train is really a space ship and you’re out in distant space.  Let’s further assume that the train and everything in it are all that exists in the universe.  Now, answer this question:

Where are you?

The question doesn’t make any sense, does it?  All you can really say is where you are on the train.  You can’t really say where the train is!  In order for you to give a location of the train, there has to be something else “out there”.  Then, you could say the train is X miles from that other object.  That’s about all you could say and still make any sense about the train’s location.

Let’s get back to the train being the only object in the universe (along with the stuff and people on the train).  Now, answer this question:

How fast is the train going?

Again, this has no meaning.  You can’t answer it because it doesn’t make any sense.  You could only answer that question if there’s something else “out there” and you can see it going by while looking out the train’s windows.  Then, you could only say how fast you’re moving towards or away from the other object.  You couldn’t even say whether it was YOU or the OTHER object that was moving… Or BOTH, could you?  That’s because speed is relative.  It’s relative to some other object.  Just like standing on the back of a big flatbed truck traveling at 50 mph and holding a baseball.  How fast is the baseball going?  Someone standing on the street would say it’s going 50mph.  You might agree, but then you might say, “I’m holding it in my hand, therefore, it’s not moving.  It’s speed is zero.”  You’d both be right.  What if you throw the baseball forward at 50 mph.  How fast is the ball going?  Well, relative to you and the truck, it’s going 50mph.  If you throw it forward in the same direction the truck is traveling, someone stationary on the ground would say 100mph.  You’re both right because the speed of the ball is 100mph relative to the ground and 50mph relative to you and the truck.  Suppose you’re on the equator driving east.  How fast is the ball going to someone standing on the north pole?  Well, since the Earth rotates at roughly 1000mph at the equator, the ground at the equator is moving at 1000mph and your truck is moving at 1050mph and the ball is moving at 1100mph.  But, how fast is the ball going relative to the center of the sun?  The Earth orbits the sun at roughly 30km/s.  So the ball would be going at Earth’s orbit speed, plus it’s rotation speed (if it were midnight at the location on Earth of the ball and truck), plus the speed of the truck, plus the speed of the ball.  If it were noon, it’d be Earth’s orbit speed minus its rotation speed, minus truck speed, minus ball speed.  What about relative to the center of the Galaxy?  What about relative to the center of another Galaxy?  What about relative to the universe?  Ah ha!  There’s no answer to the last question, not even a relative one.  The universe has no center, no preferred frame, no preferred coordinate system.  The universe just “is”.

A Thought Experiment:

This is where it starts getting weird… in just a few moments.  Now, back to the train in space.  Imagine some unknown source of a flash right beside the front of the train… just a few inches to the right edge of the train, by the engine car.  Now, you’ve got two timing mechanisms on the train.  One at the front of the train and one in the back of the train.  They can time the precise moment they detect a flash of light.  Also assume you have two perfect clocks that are perfectly synchronized; one at the front of the train, hooked to the flash sensor there and the other at the back of the train, hooked to the sensor there.  Let’s say the train is 300,000 km long (one light second long).

You see the flash of light originate at the front of the train.  The front flash detector detects the flash at 12:00 noon, exactly.  The detector in the back of the train, being a full light second away, detects the flash at exactly 12:00:01 PM.  Exactly 1 second later.

You compare the time stamp recordings of both detectors and accurately determine that exactly 1 second elapsed between the front and the back detectors detecting the flash.  Now, since you know that light always travels at 300,000km/s, you can easily determine that the train is 1 light second long (300,000 km long).  As a matter of fact, you could say that distance is defined by light moving in a given amount of time, and vice versa; you could say that time is defined by how light traveled a certain distance.  When light travels 300,000 km, you know exactly 1 second has passed.  When 1 second has passed, you know that light has moved 3000,000 km.  This is always true, from every perspective.

So far, so good.  Let’s throw some freaky in there now.  Let’s add a second, identical space train.  Let’s say it’s passing you on the right at very high speed, moving in the direction of your train’s forward facing direction, parallel to your train.  Now, remember, speed is relative.  The people in the other train may believe it is they who are standing still and your train is passing them on their left, going towards their rear direction.  Both accounts are 100% identical and 100% correct.  Now, they also have 2 perfectly synchronized clocks that keep perfect time and two flash detectors… all just like your train.  If there’s a flash of light beside their front car, they’ll record the same things on their clocks as you did.  12:00 noon exactly on the front clock and 12:00:01 PM exactly on their caboose clock.

As your two trains are matched up (side by side) for just an instant, at that very instant, there’s a flash of light at what appears to be exactly the same location as the last one… just a few inches to the right of your train’s engine car.  It’s at exactly the same relative location to the other train’s engine car, except a few inches to its left (the flash is directly between the two passing trains’ engine cars).

Now, you already know how the timing results play out in your train, and you know how they play out in the other train.  But, there’s a problem!  Let’s say it’s 12:00 noon exactly again just as the flash happens and your clock in your train at the front records it as 12:00 noon exactly.  So does the front clock of the other car.  So far, so good.

As the flash of light travels towards the back of both of your trains, the other train is still moving forward.  Let’s say from your perspective, the other train is traveling at 50% light speed (or 50% c).  This means that the back of the other train and the flash of light will meet each other before the flash of light reaches your rear detector!  As a matter of fact, the back end of the other train will be roughly 1/4 of the way up from the rear of your train when that flash of light hits their rear detector!  See the problem yet?

image

Let’s say you have a 3rd flash detector location at exactly 1/4 of distance from the back of your train to the front… at exactly the spot where the flash meets the back of the caboose of the passing train.  YOUR clocks measure the flash at 12:00:00.75 PM (3/4 of a second past noon) when the light hits the back of the other train.  Several things to note:

  1. From your perspective, light has only traveled 3/4 of a light second (225,000 km).
  2. Only 3/4 of a second of time has passed!
  3. You perceive the origin of the flash as coming from the front of your train.
  4. The other train has measured a full second of time passing.
  5. The other train has measured that the light traveled a full light second (300,000 km).

You and the other train are disagreeing on both time and distance.  But, you’re both right!  Time and distance are truly relative… hence the term Relativity!

Now, let’s look at it from the perspective of passengers on the other train:

  • When your two trains are perfectly beside each other as YOUR train is racing backwards, there’s a flash of light, just outside and to the left of the front engine car.
  • The light travels a full 300,000 km to reach the back of their train.
  • One full second has passed and their perfect clocks will prove that.
  • While the light is traveling to the back of their car, YOUR train is moving backwards at 50% c and when the light reaches the back of their train, the back of their train is just now meeting up with your 3rd flash detector 1/4 of the way from the back of your train.
  • THEIR clocks have correctly determined that a full second of time has passed and that the light has traveled a full 300,000 km.
  • The light continues racing toward the back of your train as your train continues racing in the same direction as the light is traveling, but at 1/2 light speed.  Eventually the light catches up and meets the back of YOUR train.
  • The clocks on the other train correctly measure that light had to travel much more than 300,000 km to reach the back of YOUR train and that MUCH MORE than a second passed for the light to traverse the full length of YOUR train!

Whose measurements are correct?  They BOTH are!  Time and length are relative.  This disagreement in time is called, Time Dilation and it’s a real and measureable phenomenon!  In fact, it’s so real, that much of our technology works because of it.  Nuclear bombs wouldn’t work if this time dilation didn’t happen.  Nuclear energy wouldn’t work.  Our GPS satellites are traveling at roughly 4.6 miles per second.  That’s fast enough that the incredibly precise clocks on board, necessary to triangulate your position on Earth, would get out of sync with clocks on the ground because of the time dilation.  Because of this, the scientists that designed the GPS satellites had to change the speed of the clocks on board the satellites so they’d stay synchronized with the clocks on the ground!

Congratulations!  You now understand Einstein’s Theory of Special Relativity.  Check back later for Part III in my series to discuss Einstein’s Theory of General Relativity which deals with space and time distortions due to gravity.  This will be an equally strange section.  We’ll bring up black holes and why they exist and all the fun stuff you can do with them, like spaghettifying an astronaut falling into one, to name just a few.

See this image?

image_thumb26

You’ll find an actual working version of it at the bottom of this article. Please click the appropriate buttons in it to let your friends know about this article.

Check back later for updates too!

Click here to follow me on Google+.

Share