99
18
Following the best security practices, I keep a plain text file with my passwords on my hard drive. In fact, I just copied and pasted one of them to access my PPCG account.
In a lucid moment, I decide that the password should better not remain in the clipboard after its use. Since this happens to me often, I could use a program to remove the clipboard contents.
Challenge
Write a program or function that deletes or overwrites any text contained in the clipboard, using a programming language of your choice.
Additional details:
If your system has several clipboards, you can write the program for any one of them. The only requirement is that it must be possible for the user to copy and paste text using that clipboard.
If your clipboard keeps a history of recent copied entries, assume the most recent entry.
If your answer is specific to an operating system or clipboard, indicate it in the title of your post, together with the used language.
The clipboard is guaranteed to contain text when your program is run. You can either delete the contents from the clipboard, or overwrite it with something else (not necessarily text). The only requirement is that after running the program, pasting from the clipboard will not produce the original text.
If you choose to overwrite with some fixed or randomly chosen text, you can assume that the previous clipboard contents are different from that text, so the password is effectively removed. In other words, disregard the possibility that the filler text coincides with the password.
The program should not have any side-effects like restarting the system, closing programs, shutting down the computer, or freezing it. After your program is run, the user should be able to keep using the computer as normal, only with the password removed from the clipboard. Also, standard loopholes are forbidden.
Shortest code in bytes wins.
What if the clipboard has an undetermined number of entries? – LarsW – 2017-02-26T19:27:34.713
@LarsW Can you please ellaborate or give an example? – Luis Mendo – 2017-02-26T19:43:17.143
Well, on my computer I can access the last ~10 I copied/selected, but I can imagine that number being different on different systems. I don't know if this matters at all, so that's why I asked. – LarsW – 2017-02-26T20:00:06.203
@LarsW Oh, I see. You can assume the most recent entry. Edited into the text – Luis Mendo – 2017-02-26T20:10:18.197
21
On a more serious note: Use something like keepass to do that for you.
– flawr – 2017-02-26T21:14:09.00317"Disregard the possibility that the filler text coincides with the password." Solution:
, 0 bytes. Overwrites the password with itself. – Esolanging Fruit – 2017-02-27T03:10:09.417
2@Challenger5 but that's only If you choose to overwrite with some fixed or randomly chosen text – Luis Mendo – 2017-02-27T10:08:08.780
11The very worst part about this question is that I can completely relate to the intro story despite knowing that it's satirical. ...so, keepass, huh? Should look into that... – Nat – 2017-02-27T11:01:41.857
@Challenger5 That wouldn't be a full Java program or function ;) – user41805 – 2017-02-28T10:22:10.823
Or you could...you know...copy something else?! Erase the last thing copied??!! Ha. Ha. Ha. – PlanetAstro_William – 2017-03-03T04:38:14.910