Mercurial > cgi-bin > hgweb.cgi > PassMan
comparison src/main/kotlin/name/blackcap/passman/Entry.kt @ 0:a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sun, 11 Sep 2022 16:11:37 -0700 |
parents | |
children | 3c792ad36b3d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a6cfdffcaa94 |
---|---|
1 package name.blackcap.passman | |
2 | |
3 import java.lang.StringBuilder | |
4 import java.sql.Connection | |
5 import java.sql.PreparedStatement | |
6 import java.util.Date | |
7 | |
8 class Entry(val name: String, val username: String, val password: CharArray, val notes: String, | |
9 val created: Date? = null, val modified: Date? = null, val accessed: Date? = null) { | |
10 | |
11 companion object { | |
12 fun withPromptedPassword() = Entry( | |
13 name = _getName(), | |
14 username = _getUsername(), | |
15 password = _getPassword(), | |
16 notes = _getNotes() | |
17 ) | |
18 | |
19 fun withGeneratedPassword(length: Int, allowSymbols: Boolean, verbose: Boolean): Entry { | |
20 val generated = generate(length, allowSymbols) | |
21 if (verbose) { | |
22 println("Generated password: $generated") | |
23 } | |
24 return Entry( | |
25 name = _getName(), | |
26 username = _getUsername(), | |
27 password = generated, | |
28 notes = _getNotes() | |
29 ) | |
30 } | |
31 | |
32 private fun _getName() = mustReadLine("Name of site: ") | |
33 | |
34 private fun _getUsername() = mustReadLine("Username: ") | |
35 | |
36 private fun _getPassword() = mustGetPassword("Password: ", verify = true) | |
37 | |
38 private fun _getNotes() = readLine("Notes: ") | |
39 } | |
40 | |
41 fun print(redactPassword: String? = null) { | |
42 println("Name of site: $name") | |
43 println("Username: $username") | |
44 if (redactPassword == null) { | |
45 printPassword(password) | |
46 } else { | |
47 println("Password: $redactPassword") | |
48 } | |
49 } | |
50 | |
51 fun printLong(redactPassword: String? = null) { | |
52 print(redactPassword) | |
53 println("Notes: $notes") | |
54 printDate("Created", created) | |
55 printDate("Modified", modified) | |
56 printDate("Accessed", accessed) | |
57 } | |
58 | |
59 private fun printDate(tag: String, date: Date?) { | |
60 kotlin.io.print("${tag}: ") | |
61 if (date == null) { | |
62 println("never") | |
63 } else { | |
64 println(ISO8601.format(date)) | |
65 } | |
66 } | |
67 | |
68 } |