Git Product home page Git Product logo

abbasjoyia99 / keychainmanager Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 16 KB

The KeychainManager is a library that provides a convenient interface for securely managing email and password data in the keychain.

Home Page: https://ghullamabbas.mystrikingly.com/

Swift 100.00%
ios keychain keychain-wrapper password-safety sensitive-data swift swift-package-manager iosdeveloper iosdevelopment keychain-access

keychainmanager's Introduction

KeyChainManager

KeychainManager is a Swift library that provides a convenient way to securely store and retrieve data in the keychain. It allows you to save and retrieve email and password values associated with unique keys. The library utilizes the Security framework to interact with the keychain.

Installation

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding KeyChainManager as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/abbasjoyia99/KeyChainManager.git", .upToNextMajor(from: "2.0.1"))
]

Manually

If you prefer not to use any of the aforementioned dependency managers, you can integrate KeychainManager into your project manually.

1 Download zip file
2 Open KeyChainManager/Sources/KeyChainManager
3 Drag and drop KeyChainManager.swift file into project

Usage

To use the KeychainManager library, follow these steps:

1 Import the KeychainManager module in the file where you want to use it:

import KeychainManager

Generic Data

Saving Generic Data

To save data securely in the keychain, use the saveData(data:forKey:) method:

let keychain = KeychainManager.shared
let email = "[email protected]"

// Save the email securely in the keychain
let success = keychain.saveData(data: email, forKey: "userEmail")

if success {
    print("Email saved successfully.")
} else {
    print("Failed to save email.")
}

Retrieving Generic Data

To retrieve data from the keychain, use the getData(type:forKey:) method:

let keychain = KeychainManager.shared

// Retrieve the saved email from the keychain
if let email: String = keychain.getData(type: String.self, forKey: "userEmail") {
    print("Retrieved email: \(email)")
} else {
    print("Email not found in the keychain.")
}

Updating Generic Data

To update existing data in the keychain, use the updateData(data:forKey:) method:

let keychain = KeychainManager.shared
let newEmail = "[email protected]"

// Update the email in the keychain
let success = keychain.updateData(data: newEmail, forKey: "userEmail")

if success {
    print("Email updated successfully.")
} else {
    print("Failed to update email.")
}

Deleting Generic Data

To delete data from the keychain, use the deleteData(forKey:) method:

let keychain = KeychainManager.shared

// Delete the email from the keychain
let success = keychain.deleteData(forKey: "userEmail")

if success {
    print("Email deleted successfully.")
} else {
    print("Failed to delete email.")
}

2 Save data securely in the keychain:

let key = "emailKey"
let email = "[email protected]"

let success = KeychainManager.shared.saveEmail(email: email, forKey: key)
if success {
    print("Email saved successfully!")
} else {
    print("Failed to save email.")
}

3 Retrieve data securely from the keychain:

let key = "emailKey"

if let email = KeychainManager.shared.getEmail(forKey: key) {
    print("Retrieved email: \(email)")
} else {
    print("Email not found in the keychain.")
}

4 Update data in the keychain:

let key = "emailKey"
let newEmail = "[email protected]"

let success = KeychainManager.shared.updateEmail(newEmail: newEmail, forKey: key)
if success {
    print("Email updated successfully!")
} else {
    print("Failed to update email.")
}

5 Delete data from the keychain::

let key = "emailKey"

let success = KeychainManager.shared.deleteEmail(forKey: key)
if success {
    print("Email deleted successfully!")
} else {
    print("Failed to delete email.")
}

API Reference

The KeychainManager class provides the following methods:

saveEmail(email: String, forKey: String) -> Bool: Saves the specified email securely in the keychain.

savePassword(password: String, forKey: String) -> Bool: Saves the specified password securely in the keychain.

getEmail(forKey: String) -> String?: Retrieves the specified email securely from the keychain.

getPassword(forKey: String) -> String?: Retrieves the specified password securely from the keychain.

updateEmail(newEmail: String, forKey: String) -> Bool: Updates the specified email securely in the keychain.

updatePassword(newPassword: String, forKey: String) -> Bool: Updates the specified password securely in the keychain.

deleteEmail(forKey: String) -> Bool: Deletes the specified email securely from the keychain.

deletePassword(forKey: String) -> Bool: Deletes the specified password securely from the keychain.

Requirements

iOS 9.0+ / macOS 10.12+ / tvOS 9.0+ / watchOS 2.0+

Xcode 11.0+

Swift 5.0+

Contributing

Contributions, issues, and feature requests are welcome! See Contributors for details.

###Contributions Any contribution is more than welcome! You can contribute through pull requests and issues on GitHub.

Show your Support

Give a star if this project helped you.

Contact

[email protected]

keychainmanager's People

Contributors

abbasjoyia99 avatar ghullamabbasjoyia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

keychainmanager's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.