π‘οΈ SecureVault Login Manager β a reusable Kotlin console tool that demonstrates the five scoped functions clearly while staying practical and open for extension (logging, security modules, user management, etc.).
/*
* =============================================================
* SecureVault Login Manager
* -------------------------------------
* Author : Muhammad Arslan (cosmichackerx)
* Language : Kotlin
* Purpose : Demonstrate Kotlin Scoped Functions (let, run, apply, with, also)
* License : MIT License
* =============================================================
*/
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
// =======================
// Data Model
// =======================
data class User(
var username: String = "",
var email: String = "",
var password: String = ""
) {
fun securityScan(): String {
// Simulate security checks
val firewall = true
val malware = true
val dataIntegrity = true
return if (firewall && malware && dataIntegrity) {
"β
All systems secure"
} else if (!firewall && !malware && !dataIntegrity) {
"β οΈ Warning: Suspicious activity detected"
} else {
"π¨ Critical error: System not fully secure"
}
}
fun showDashboard() {
println("\nπ ==== User Dashboard ====")
println("Username : $username")
println("Email : $email")
println("Status : Logged in successfully β
")
println("============================")
}
}
// =======================
// Main Application
// =======================
fun main() {
println("π‘οΈ Welcome to SecureVault Login Manager")
println("=======================================")
// ISO 8601 formatted time stamp
val currentTime = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
// STEP 1: apply β Initialize user
val user = User().apply {
username = "Muhammad"
email = "cosmichackerx@gmail.com"
password = "1234567"
println("\n[apply] Initializing user profile...")
}
// STEP 2: also β Log activity / audit
user.also {
println("[also] ${it.username} attempted login at $currentTime using email: ${it.email}")
}
// STEP 3: run β Perform security checks & get result
val scanResult = user.run {
println("\n[run] Performing security scan for user '$username'...")
securityScan()
}
println("[run] Result: $scanResult")
// STEP 4: let β Validate data safely
val verifiedUser = user.let {
println("\n[let] Validating user data...")
if (it.email.isNotEmpty() && it.password.isNotEmpty()) {
println("β
Credentials verified for ${it.username}")
it
} else {
println("β Invalid credentials! Access denied.")
null
}
}
// STEP 5: with β Display dashboard if login succeeded
if (verifiedUser != null) {
with(verifiedUser) {
println("\n[with] Loading user dashboard...")
showDashboard()
println("β¨ Welcome back, $username! Stay safe and secure.")
}
} else {
println("\nUser validation failed. Exiting SecureVault.")
}
println("\nπ§ Program executed successfully.")
}# π‘οΈ SecureVault Login Manager
A practical **Kotlin console application** demonstrating all **five scoped functions** β `let`, `run`, `apply`, `with`, and `also` β through a real-world scenario of a secure login and system verification process.
---
## π Overview
`SecureVault Login Manager` simulates a login environment where:
1. A **user** object is created and configured.
2. Actions are **logged** for auditing.
3. The system performs a **security scan**.
4. User data is **validated** safely.
5. A **dashboard** is displayed for successful logins.
Itβs a simple yet powerful way to understand **Kotlin scoped functions in action**, built for learners, developers, and educators alike.
---
## π§ Concepts Covered
| Function | Purpose | Behavior | Returns |
|-----------|----------|-----------|----------|
| `apply` | Initialize / setup object | Access with `this` | The object itself |
| `also` | Log side effects | Access with `it` | The object itself |
| `run` | Execute block and return result | Access with `this` | Lambda result |
| `let` | Transform or validate safely | Access with `it` | Lambda result |
| `with` | Operate on non-null object | Access with `this` | Lambda result |
---
## πΌ Real-World Analogy
| Function | Real-Life Role | Example |
|-----------|----------------|----------|
| `apply` | Filling your ID form | Configure user details |
| `also` | CCTV log entry | Log login attempt |
| `run` | Security scan | Check system safety |
| `let` | Guard validation | Verify credentials |
| `with` | Vault access | Open user dashboard |
---
## π Project Structure
SecureVault-Login-Manager/
β
βββ SecureVault.kt β Main Kotlin source file
βββ LICENSE β MIT License file
βββ README.md β Project documentation (this file)
git clone https://github.com/cosmichackerx/SecureVault-Login-Manager.git
cd SecureVault-Login-Managerkotlinc SecureVault.kt -include-runtime -d SecureVault.jarjava -jar SecureVault.jarπ‘οΈ Welcome to SecureVault Login Manager
=======================================
[apply] Initializing user profile...
[also] Muhammad attempted login at 2025-10-23T10:15:30 using email: cosmichackerx@gmail.com
[run] Performing security scan for user 'Muhammad'...
β
All systems secure
[let] Validating user data...
β
Credentials verified for Muhammad
[with] Loading user dashboard...
π ==== User Dashboard ====
Username : Muhammad
Email : cosmichackerx@gmail.com
Status : Logged in successfully β
============================
β¨ Welcome back, Muhammad! Stay safe and secure.
π§ Program executed successfully.
This project is designed to help Kotlin learners understand:
- Null safety and scope isolation
- Object initialization and chaining
- Readable code structure using scoped functions
- Realistic security-themed programming patterns
π€ Muhammad Arslan π§ Email: cosmichackerx@gmail.com π» GitHub: @cosmichackerx π Project Type: Educational / Open Source
This project is licensed under the MIT License β youβre free to use, modify, and share it for learning or development purposes. See the LICENSE file for details.
Copyright (c) 2025 Muhammad Arslan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...
Kotlin Scoped Functions apply also run let with Kotlin Tutorial Cybersecurity Educational Project Console App OOP
Want to make SecureVault even cooler?
- Fork the repo
- Add new features (e.g., password encryption, login attempts counter)
- Submit a pull request β¨