PS: Login Cmdlet
This is one of the first cmdlets that I wrote for personal use.
If you’re me, then you’re probably skeptic of being blasted by ads based off of that wristwatch that you purchased as a gift. Consequently, you turn to anonymous browsing, or, in case you also like living under a rock (like me), you choose to log in/out of your social media accounts everytime.
Regardless of whether you choose to keep logged in or not, having a utility that lets you quickly log in/out of your accounts without risking password leaks or you bearing the burden of remembering each password can come in handy. Also, having such a utility allows you to set as difficult a password as you like, and is suited for tasks such as paying your electricity bills, or your credit-card bills.
Unlike Jim Sarbh, I’m not a fan of paying my bills. And I really hope you aren’t either. If you are, then you have no use being here. Just saying. 😅
Anyway, let’s talk structure. We’ll import all necessary info from a CSV file such as this:
# myLogins.csv
Site,Link,Username,Password
Amazon,https://www.amazon.in/gp/navigation/redirector.html/ref=sign-in-redirect,USERNAME,PASSWORD
GMail,https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com,USERNAME,PASSWORD
GDrive,https://accounts.google.com/signin/v2/identifier?continue=http%3A%2F%2Fdrive.google.com,USERNAME,PASSWORD
As you can see, I have put separate links for GMail & GDrive. This allows me to get directly onto my desired page once the login shenanigan is over with. I know, not very smart, but it gets the job done, so what the hell!
In sincerity, I just meant to show that software-suites (such as GSuite) allows separate login pages for individual apps. Hence, you can store logins for ones that you regularly use.
Now, in our cmdlet, we’ll query the CSV file using the sitename, and open up the corresponding login page with the credentials copied to clipboard.
A -List
switch simply lists all the available entries.
function Get-Login{
[cmdletBinding()]
[Alias('glog')]
param(
[string]$Site,
[switch]$List,
[switch]$PassThru
)
$logins = Import-Csv $myLogins
if ($List) {$logins.site}
$match = $logins | where site -eq $Site
if (-not $PassThru -and -not $List) {firefox $match.link}
$match.username,$match.password | Set-Clipboard
}
Here’s the cmdlet in action: (jump to 1:54)