-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
62 lines (52 loc) · 1.7 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { useState } from "react";
import { View, Text, Image, TouchableOpacity } from "react-native";
import { StatusBar } from "expo-status-bar";
import Slider from "@react-native-community/slider";
import Clipboard from "expo-clipboard";
import styles from "./src/styles";
import img from "./src/assets/logo.png";
let charset =
"0123456789abcdefghijklmnopqrstuvwxyz#!$%(&*)[-_={+@]<?}>/ABCDEFGHIJKLMNOPQRSTUVWXYZ";
export default function App() {
const [password, setPassword] = useState("");
const [size, setSize] = useState(13);
function generatePass() {
let pass = "";
for (let i = 0, n = charset.length; i < size; i++) {
pass += charset.charAt(Math.floor(Math.random() * n));
}
setPassword(pass);
}
function copyPass() {
Clipboard.setString(password);
alert("Senha copiada com Sucesso!");
}
return (
<View style={styles.container}>
<StatusBar style="dark" />
<Image source={img} style={styles.logo} />
<Text style={styles.title}> {size} Caracteres</Text>
<View style={styles.area}>
<Slider
style={styles.slider}
minimumValue={4}
maximumValue={20}
minimumTrackTintColor="#6520BA"
maximumTrackTintColor="#8C8C8C"
value={size}
onValueChange={(valor) => setSize(valor.toFixed(0))}
/>
</View>
<TouchableOpacity style={styles.button} onPress={generatePass}>
<Text style={styles.buttonText}>Gerar Senha</Text>
</TouchableOpacity>
{password !== "" && (
<View style={styles.area}>
<Text style={styles.password} onLongPress={copyPass}>
{password}
</Text>
</View>
)}
</View>
);
}