Based on how you're using t[:username] and t[:password], why bother checking if USERNAME is nil or empty when you can simply to:

	 t[:username] = datastore['USERNAME'].to_s

Because at line 284, you're defaulting username to '' anyway.  Why not just do in at line 124?